Skip to content

jacksonofalltrades/pydeepstream

Repository files navigation

pydeepstream

Python driver for Deepstream.io on Twisted with Autobahn. This project provides an API interface to communicate with a Deepstream server for Twisted applications.

Getting Started

Installing

pip install -r requirements.txt
pip install ./

Or, alternatively,

pip install --process-dependency-links ./

Usage

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.

from deepstreampy_twisted.interface import DeepstreamClient

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({})) # .connect accepts a callback once connection is established to trigger authentication
client.whenAuthenticated(client.event.emit, 'chat', 'hello world') # Submit "hello world" to any listeners on the "chat" topic
client.whenAuthenticated(client.event.subscribe, 'chat', the_callback) # "Subscribe to the "chat" topic; upon receiving an event, call the callback we defined earlier
reactor.callLater(2, client.disconnect) # Two seconds after running the reactor, disconnect.
reactor.run()

For further reading, start in the DeepstreamClient class in deepstreampy_twisted/interface.py

Also check out the functions in EventEmitter, from which DeepstreamClient inherits.
The events available are defined upstream in deepstreampy.constants.event.
These events are distinct from the Deepstream.io Events feature; they are used only internally.

DeepstreamClient also makes some upstream features available as properties. To investigate their interface, see the code upstream:

Testing with Docker image for server

docker-compose up

Running the tests

First, install the extra dev requirements
pip install -r dev_requirements.txt
Then you may run the tests
trial tests

Built With

Authors

  • Will Crawford - Adaptation to Twisted; connection layer in Twisted + interface to deepstreampy - Sapid

License

This project is licensed under MIT - see the LICENSE file for details.

About

Python driver for Deepstream.io

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages