Python client library for Spire.io APIs.
Here's an example using the message service.
client = spire.Client(async=False, key=key) # key is your account key
session = client.session()
channel = session.channel('foo', 'the foo channel')
channel.publish('What hath Shark wrought?')
Let's create a second session and get our messages.
client2 = spire.Client(async=False, key=key) # key is your account key
session2 = client2.session()
channel2 = session2.channel('foo', 'the foo channel')
channel2.subscribe() # => 'What hath Shark wrought?'
You can also assign listener blocks to a subscription which will be called with
each message received. async
=True indicates your system has libevent/gevent
installed for evented callbacks.
client3 = spire.Client(async=True, key=key) # key is your account key
session3 = client3.session()
channel3 = session3.channel('foo', 'the foo channel')
def get_callback(channel_name):
def _callback(events):
print events
return _callback
channel3.subscribe(callback=get_callback("foo"))
(up-to-date dependencies will always be in setup.py)
- Requests is the only external dependency on Python 2.6+
- If you are running Python 2.5, you will need to install simplejson
- Asynchronous operation requires gevent (which in turn requires greenlet and libevent) - if you are running Debian or Ubuntu the system package (python-gevent) is recommended as installing from source via pip may lead to segfaults, and nobody likes those.