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 hashes)

Uploaded Source

Built Distribution

django_channels_handlers-0.1.0-py3-none-any.whl (5.1 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