Demultiplexer for Django Channels
Project description
(De)multiplexer for Django Channels 3 (and 2)
Functionality
Channels Demultiplexer provides a standard way to multiplex different data streams over a single websocket.
It expects JSON-formatted WebSocket frames with two keys, stream and payload (both configurable). It matches the stream against a mapping to find a consumer and subsequently forwards the message. Consumers do not require any modifications in order to be plugged in to a (de)multiplexer, so you can hook them directly in the routing.py file as well as in a (de)multiplexer.
Quickstart
Install using pip:
$ pip install channels-demultiplexer
Add channels_demultiplexer to your INSTALLED_APPS
INSTALLED_APPS = [
# channels_demultiplexer can be in any position in the INSTALLED_APPS list.
"channels_demultiplexer",
]
Create a demultiplexer in demultiplexer.py:
from channels_demultiplexer.demultiplexer import WebsocketDemultiplexer
from .consumers import EchoConsumer, AnotherConsumer
class Demultiplexer(WebsocketDemultiplexer):
# Wire your async JSON consumers here: {stream_name: consumer}
consumer_classes = {
"echo": EchoConsumer,
"other": AnotherConsumer,
}
Add the demultiplexer to your Channels routing configuration:
from channels.routing import ProtocolTypeRouter, URLRouter
from django.conf.urls import url
from django.core.asgi import get_asgi_application
from .demultiplexer import Demultiplexer
application = ProtocolTypeRouter({
"http": get_asgi_application(),
"websocket": URLRouter([
url(r"^/$", Demultiplexer.as_asgi()),
])
})
Documentation
For more information on installation and configuration see the documentation at:
Compatibility
channels |
channels_demultiplexer |
---|---|
v3.x |
latest |
v2.x |
v1.0.1 |
Issues
If you have questions or have trouble using the app please file a bug report at:
Contributions
It is best to separate proposed changes and PRs into small, distinct patches by type so that they can be merged faster into upstream and released quicker:
features,
bugfixes,
code style improvements, and
documentation improvements.
All contributions are required to pass the quality gates configured with the CI. This includes running tests and linters successfully on the currently officially supported Python and Django versions.
The test automation is run automatically by Travis CI, but you can run it locally with the tox command before pushing commits.
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
Built Distribution
File details
Details for the file channels-demultiplexer-2.2.0.tar.gz
.
File metadata
- Download URL: channels-demultiplexer-2.2.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e024783362ededb7673f37b99b4e930a0eb52ad637722efef1d10be89350b0b8 |
|
MD5 | 87ad587232e5bd187341dccf59043dfc |
|
BLAKE2b-256 | 89cb9e616e9cef864138aace3b3b8c6d30366ab8676cc3f610f08329f46df9fc |
File details
Details for the file channels_demultiplexer-2.2.0-py3-none-any.whl
.
File metadata
- Download URL: channels_demultiplexer-2.2.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7797657c7a45e2dcd6da34545671df67354c983e1d8ce37e28c5c04964517315 |
|
MD5 | 90f9a2341fecb822ef32805a3db8b983 |
|
BLAKE2b-256 | c2c60bb0e693897ee850992886c1f96689579f1a5d06ee50dbaf5c09c67cad37 |