Skip to main content

Demultiplexer for Django Channels

Project description

GitHub PyPI release Documentation Build Status Coverage

(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:

https://channels-demultiplexer.readthedocs.io/

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:

https://github.com/csdenboer/channels-demultiplexer/issues

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

channels-demultiplexer-2.2.0.tar.gz (6.8 kB view hashes)

Uploaded Source

Built Distribution

channels_demultiplexer-2.2.0-py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 3

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