Mease: Websocket integration made easy for Django
Project description
django-mease
============
Work in progress
Websocket integration made easy for Django using Tornado, Redis PUB/SUB and easy to use callback registry mechanism.
## Installation
### Dependencies (Debian & Ubuntu)
```
sudo apt-get install redis-server python-dev
```
### Install django-mease
```
pip install django-mease
```
### Add mease to your INSTALLED_APPS
```python
INSTALLED_APPS = (
...
'mease',
)
```
## Usage
### Start websocket server
`python manage.py start_websocket_server`
### Register callbacks
Create `mease_registry.py` files to register your callbacks (the file must be located in an installed app):
```python
import mease
def receive_websocket_message(client, message, clients_list):
for c in clients_list:
c.write_message(message)
mease.receiver(receive_websocket_message)
def send_websocket_message(channel, message, clients_list):
for c in clients_list:
c.write_message(message)
mease.sender(send_websocket_message, channels=['websocket'])
```
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 channel
3. the message content
A sender function can be registered for a list of channels, otherwise it is registered for all channels.
### Publish
Use `mease.publish` to publish from anywhere in your code :
```python
import mease
mease.publish('websocket', "Hello world !")
```
This will call all sender functions registered on the 'websocket' channel.
============
Work in progress
Websocket integration made easy for Django using Tornado, Redis PUB/SUB and easy to use callback registry mechanism.
## Installation
### Dependencies (Debian & Ubuntu)
```
sudo apt-get install redis-server python-dev
```
### Install django-mease
```
pip install django-mease
```
### Add mease to your INSTALLED_APPS
```python
INSTALLED_APPS = (
...
'mease',
)
```
## Usage
### Start websocket server
`python manage.py start_websocket_server`
### Register callbacks
Create `mease_registry.py` files to register your callbacks (the file must be located in an installed app):
```python
import mease
def receive_websocket_message(client, message, clients_list):
for c in clients_list:
c.write_message(message)
mease.receiver(receive_websocket_message)
def send_websocket_message(channel, message, clients_list):
for c in clients_list:
c.write_message(message)
mease.sender(send_websocket_message, channels=['websocket'])
```
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 channel
3. the message content
A sender function can be registered for a list of channels, otherwise it is registered for all channels.
### Publish
Use `mease.publish` to publish from anywhere in your code :
```python
import mease
mease.publish('websocket', "Hello world !")
```
This will call all sender functions registered on the 'websocket' channel.
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
django-mease-0.1.7.tar.gz
(6.7 kB
view details)
File details
Details for the file django-mease-0.1.7.tar.gz
.
File metadata
- Download URL: django-mease-0.1.7.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 001d71a575812f1affffde3112fe41b3fba01b6805b70eb36fce700fd5b52fe0 |
|
MD5 | 7f5aa1cc4a6b2e19ade5aa6f620e4f13 |
|
BLAKE2b-256 | 03cd99dd20bdd17d05680e05cac68fd99538ea6a231a7f50b5e3532c8a5266a8 |