Skip to main content

Django Channels, without the Pain 💊

Project description

Latest PyPI version https://travis-ci.com/joshua-s/django-channels-handlers.svg?branch=master

Django Channels, without the Pain 💊

Requirements

  • Django>=2.1

  • channels>=2.2

  • pydantic>=0.32

Usage

Install django-channels-handlers from pypi:

pip install django-channels-handlers

Create a message handler

from channels_handlers.handlers import MessageHandler
# For async, import AsyncMessageHandler


class ChatHandler(MessageHandler):
    namespace = "chat"
    handled_types = {
        "chat.message": "receive_message",
    }
    models = {
        "chat.message": pydantic_models.Message,
    }

    def receive_message(self, message):
        # Do something with the message
        pass

Import ConsumerHandlerMixin and add it to your Django Channels consumer

from channels_handlers.consumers import ConsumerHandlerMixin
# For async, import AsyncConsumerHandlerMixin
from channels.generic.websocket import JsonWebsocketConsumer


class MyConsumer(ConsumerHandlerMixin, JsonWebsocketConsumer):
    handler_classes = [ChatHandler]

Compatibility

django-channels-handlers is compatible with Python 3.6+, Django 2.1+, and Django Channels 2.2+.

License

django-channels-handlers is licensed under the MIT License.

Authors

django-channels-handlers was written by Josh Smith.

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-channels-handlers-0.1.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

django_channels_handlers-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file django-channels-handlers-0.1.0.tar.gz.

File metadata

  • Download URL: django-channels-handlers-0.1.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for django-channels-handlers-0.1.0.tar.gz
Algorithm Hash digest
SHA256 697b29f5686355ee82943edd91c1f925055f913f0bb42391b47c92ac773c3541
MD5 5198f7c78574de625063db46df79d40b
BLAKE2b-256 1702e7bb055ddcc14fc97cd52bc87b5d1a77618b39f95929a7bffbb33430ec88

See more details on using hashes here.

Provenance

File details

Details for the file django_channels_handlers-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_channels_handlers-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for django_channels_handlers-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a111e09fdc7adbb1f6ccf8bd4766defd3c2d609db080eed42b945a84e871c15c
MD5 869154ede0a3f80f135206e0e8c1224a
BLAKE2b-256 48b5cb1ea89b65f7dfe37d9f2f434303085b70660f9395dfb895ba6e5b4c19cc

See more details on using hashes here.

Provenance

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