Skip to main content

django-mease: Websocket integration made easy for Django

Project description

Work in progress.

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

See a full working example here

RTD INCOMING SHORTLY

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.9.tar.gz (3.9 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for django-mease-0.1.9.tar.gz
Algorithm Hash digest
SHA256 e0af82373110f3e0c5f9a5f287a3d91ab7e899fb939cde871950da010437a49c
MD5 4b756fad99e218e1093e45cc3ceb69de
BLAKE2b-256 47d7c287cf0640cc64e9e9c4e815887099a92286aa7d4cb293476225ed3fe873

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