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/

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

channels_demultiplexer-2.0.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file channels-demultiplexer-2.0.0.tar.gz.

File metadata

  • Download URL: channels-demultiplexer-2.0.0.tar.gz
  • Upload date:
  • Size: 6.4 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

Hashes for channels-demultiplexer-2.0.0.tar.gz
Algorithm Hash digest
SHA256 24cc706f94a8377ad82615afc890bf7460500a51059ef66bedb3fd41a4ade43b
MD5 b4f6c6bff9e5543ec9d5a6c57655f096
BLAKE2b-256 3731e81901ac750951fcab4cd7c4ea9b36b5637ce4879ed0f1ad0fcc625b36a5

See more details on using hashes here.

File details

Details for the file channels_demultiplexer-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: channels_demultiplexer-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.1 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

Hashes for channels_demultiplexer-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 085b7c109a8335c795ace0b127414adbeb32d979592654a21a14e78fa2fe3a3d
MD5 67e99c13abda9fae5c2058c866ccff38
BLAKE2b-256 d0400e783a4ba21a268996fb65c143b36a5f129dfc6f610387c57ec7c45eb515

See more details on using hashes here.

Supported by

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