Websocket server using Twisted/Autobahn with an easy to use callback registry mechanism
See django-mease, django-mease-example or flask-mease-example for working examples.
Installation
Use pip to install the latest mease version :
pip install mease
mease comes with two backends :
Redis
To use Redis backend, install these dependencies :
sudo apt-get install redis-server pip install redis
Refer to the Redis documentation to configure your server.
RabbitMQ
To use RabbitMQ backend, install these dependencies :
sudo apt-get install rabbitmq-server pip install kombu
Refer to the RabbitMQ documentation to configure your server.
Quickstart
Create a file where you can write your callbacks and register them :
from mease import Mease
from mease.backends.redis import RedisBackend
# OR from mease.backends.rabbitmq import RabbitMQBackend
from uuid import uuid4
mease = Mease(RedisBackend)
@mease.opener
def example_opener(client, clients_list):
# Do stuff on client connection
client.storage['uuid'] = str(uuid4())
@mease.closer
def example_closer(client, clients_list):
# Do stuff on client disconnection
print("Client {uuid} disconnected".format(uuid=client.storage.get('uuid')))
@mease.receiver(json=True)
def example_receiver(client, clients_list, message):
# Do stuff on incoming client message
pass
@mease.sender(routing='mease.demo')
def example_sender(routing, clients_list, my_tuple):
# Do stuff on outgoing message
pass
if __name__ == '__main__':
# Start websocket server
mease.run_websocket_server()
Remember to run the websocket server from the mease instance where you registered your callbacks.
In your code, you can now call the mease publish method to send a message to websocket clients :
from mease import Mease
from mease.backends.redis import RedisBackend
mease = Mease(RedisBackend)
# ...
mease.publish('mease.demo', my_tuple=("Hello", "World"))
That’s it ! You are now able to send messages from your web server to your websocket server in a cool way !
Metadata
Release files for mease 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mease-0.2.0.tar.gz | 8.8 kB | Details |
Release files / mease-0.2.0.tar.gz
| Download URL | mease-0.2.0.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d65dd1cc43233e3244739c4d63d0facb0ead3e3d9ee46b9cd1a9a76f2d26caa0
|
|
BLAKE2b-256 checksum How to use checksums |
fb2176aa475cc8d0d62267d103d235bd3a69f981ce2508d19e998e4cccec93d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |