Mease: Tornado websocket server with an easy callback registry
Project description
Websocket server using Tornado 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 toredis-mease
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 pika
Refer to the RabbitMQ documentation to configure your server.
Quickstart
Create a mease registry file where you create your callbacks and register them :
from mease import Mease
from mease.backends.redis import RedisBackend
# OR from mease.backends.rabbitmq import RabbitMQBackend
mease = Mease(RedisBackend)
@mease.opener
def example_opener(client, clients_list):
# Do stuff on client connection
pass
@mease.closer
def example_closer(client, clients_list):
# Do stuff on client disconnection
pass
@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()
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 !
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file mease-0.1.1.tar.gz
.
File metadata
- Download URL: mease-0.1.1.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ee632cc53314ad609497c46cfc958de36d58248083fd47fc388cf9273ef5bf7 |
|
MD5 | fc38d3a640259b6fd737e69fc54bdeb6 |
|
BLAKE2b-256 | 80c76d04764c0f7c19254cac4a0b6cc61d6254bcf3916fdd5c4d4a8be0b666de |