Skip to main content

django-mease: Websocket integration made easy for Django

Project description

Work in progress. See a full working example here.

RTD INCOMING SHORTLY

Websocket integration made easy for Django using Tornado, Redis PUB/SUB and easy to use callback registry mechanism.

Installation

Dependencies (Debian & Ubuntu)

Mease comes with Redis PUB/SUB backend by default. If you want to use it, install these dependencies :

sudo apt-get install redis-server python-dev
pip install redis toredis-mease

Install django-mease

pip install django-mease

Add mease to your INSTALLED_APPS

INSTALLED_APPS = (
  # List of your installed apps
  'djmease',
)

Usage

Start websocket server

python manage.py run_websocket_server

Register callbacks

Create mease_registry.py files to register your callbacks (the file must be located in an installed app):

from djmease import mease

@mease.receiver
def receive_websocket_message(client, message, clients_list):
    for c in clients_list:
        c.write_message(message)

@mease.sender(routing=['websocket'])
def send_websocket_message(channel, message, clients_list):
    for c in clients_list:
        c.write_message(message)

Receiver functions are called when a message is sent from the client.

mease.receiver functions must take 3 parameters:

  1. the client (tornado WebSocketHandler instance)

  2. the message content

  3. a list of all connected clients (list of tornado WebSocketHandler instances)


Sender functions are called when a message is sent from the server.

mease.sender functions must take 3 parameters:

  1. a list of all connected clients (list of tornado WebSocketHandler instances)

  2. the target routing

  3. the message content

A sender function can be registered for a list of routings, otherwise it is registered globally.

Publish

Use mease.publish to publish from anywhere in your code :

from djmease import mease

mease.publish('websocket', "Hello world !")

This will call all sender functions registered on the ‘websocket’ routing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-mease-0.1.8.tar.gz (4.0 kB view details)

Uploaded Source

File details

Details for the file django-mease-0.1.8.tar.gz.

File metadata

File hashes

Hashes for django-mease-0.1.8.tar.gz
Algorithm Hash digest
SHA256 d4f8eefa8d4af692b048f5b21e67138bfaaf8250276e804e4eee8df8cac54787
MD5 83155e88f30817dbeda8c419d2a2fac5
BLAKE2b-256 37d51f756e8c43791d2f2b5dada6f28c26606082a0585b58e1cc5f9f2d138259

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page