Django Channels, without the Pain 💊
Project description
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.
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 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 697b29f5686355ee82943edd91c1f925055f913f0bb42391b47c92ac773c3541 |
|
MD5 | 5198f7c78574de625063db46df79d40b |
|
BLAKE2b-256 | 1702e7bb055ddcc14fc97cd52bc87b5d1a77618b39f95929a7bffbb33430ec88 |
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | a111e09fdc7adbb1f6ccf8bd4766defd3c2d609db080eed42b945a84e871c15c |
|
MD5 | 869154ede0a3f80f135206e0e8c1224a |
|
BLAKE2b-256 | 48b5cb1ea89b65f7dfe37d9f2f434303085b70660f9395dfb895ba6e5b4c19cc |