Python 3.5+ driver for Deepstream.io on Twisted with Autobahn. This project provides an API interface to communicate with a Deepstream server for Twisted applications.
pip install -r requirements.txt
pip install ./
Or, alternatively,
pip install --process-dependency-links ./
In this example, we connect to a local Deepstream server, login anonymously, say hello to the 'chat' topic, subscribe to that topic, and then disconnect after 2 seconds.
def the_callback(message=None):
print("Received event :" + str(message))
from twisted.internet import reactor # Select your reactor
client = DeepstreamClient(url='ws://localhost:6020/deepstream', debug='verbose',) # Debug has three options: False disables it, "verbose" enables verbose mode, and any other value enables normal debug mode.
client.connect(lambda : client.login({})) # If need auth, will be {'username': 'your_username', 'password': 'your_password'}
client.whenAuthenticated(client.event.subscribe, 'chat', the_callback) # "Subscribe to the "chat" topic; upon receiving an event, call the callback we defined earlier
client.whenAuthenticated(client.event.emit, 'chat', 'hello world') # Submit "hello world" to any listeners on the "chat" topic
reactor.callLater(2, client.disconnect) # Two seconds after running the reactor, disconnect.
reactor.run()
First, install the extra dev requirements
pip install -r dev_requirements.txt
Then you may run the tests
trial tests
- Twisted Matrix - network engine
- Autobahn - provides WebSocket protocol & factory for Twisted
- deepstreampy - provides an interface for deepstreampy's non-connection-related features
- Will Crawford - Adaptation to Twisted; connection layer in Twisted + interface to - Sapid
This project is licensed under MIT - see the LICENSE file for details.