A Django package to handle notifications using Django Channels and WebSockets.
Project description
A Django application to deliver user notifications made with django-snitch using WebSockets.
Quick start
This applications works using django-channels, so, you need to integrate this with your project before to integrate django-websocket-notifications. So, to make the quick start as quick and simple as possible, we’ve made the following assumptions:
You already have integrated django-channels
You are using a channel layer, like Redis
You have a routing.py file
Your project uses DRF to deliver a RESTful API
1 Install using pip:
pip install django-websocket-notifications
2 Add “websocket_notifications” to your INSTALLED_APPS settings like this:
INSTALLED_APPS += ('websocket_notifications',)
3 Add the routing patterns to your routing.py file:
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from websocket_notifications.routing import websocket_urlpatterns
application = ProtocolTypeRouter(
{"websocket": AuthMiddlewareStack(URLRouter(websocket_urlpatterns)),}
)
4 (Optional) In order to test the integration, you can add the following view to your urls.py file to be able to access to a testing view:
urlpatterns += [
path(
"websocket-notifications/",
include(
"websocket_notifications.urls",
namespace="websocket_notifications",
),
),
]
Now, you can access to /websocket-notifications/listener/ to check the integration.
5 Add the ViewSet to the DRF router:
from websocket_notifications.api.rest_framework import NotificationGroupViewSet
router = routers.DefaultRouter()
router.register("websocket-notifications/groups", viewset=NotificationGroupViewSet)
6 Integrate with django-snitch:
from websocket_notifications.snitch.backends import WebSocketNotificationBackend
@snitch.register(EVENT)
class MyEventHandler(snitch.EventHandler):
ephemeral = True
notification_backends = [WebSocketNotificationBackend]
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
Hashes for django-websocket-notifications-1.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5a1a9679084852dda55aaadb1022e811a2da69c06dfe5a1badf2b5606222a99 |
|
MD5 | 83c04b2c8de1c38e2e038edbc226e31a |
|
BLAKE2b-256 | 2a1618e01cb3183ae9ef1fcfa96941b7ff931c033fbceeb884bb865c45c5c4f2 |
Hashes for django_websocket_notifications-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a6feffc0927e962dc7e6c81689bf03bf9d67a983642860f9bb3db85a454b583 |
|
MD5 | 70203fc8bcea3c2816f97281af476b37 |
|
BLAKE2b-256 | 05b5cd82de28034f463f6d3777ae237efd9c29f51096cee0a009d5a6c396b31b |