Helpers for using WebSockets in Django
Project description
django-ws
Helpers for using WebSockets in Django
Installation
pip install django-ws
Setup
asgi.py
Remove line: from django.core.asgi import get_asgi_application
Remove line: application = get_asgi_application()
Add to the end:
from django_ws import get_websocket_application
application = get_websocket_application()
ws_urls.py
Next to your root urls.py
create a ws_urls.py
like the example below that uses your websocket.
from django.urls import path
import myapp.ws
urlpatterns = [
path('ws', myapp.ws.MySocket),
]
Write a WebSocket
from django_ws import WebSocketHandler
class MySocket(WebSocketHandler):
async def on_open(self):
do_something_on_open()
async def on_message(self, data):
do_something_on_msg()
# send json data
self.send({"reply": "sending data back"})
async def on_close(self):
do_something_on_close()
More Features
start_ping method
coming soon
start_task method
coming soon
sleep_loop method
coming soon
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django_ws-0.7.0.tar.gz
(3.8 kB
view hashes)
Built Distribution
Close
Hashes for django_ws-0.7.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84cc83adf401078750bc71919bb6508c988a82a40e1b0353d4c5a6c74e769dd9 |
|
MD5 | 929048c6fd72e9abfd9daf6b7240006e |
|
BLAKE2b-256 | 742ce8e95f22586b4826959ea8137b84ee9a5bf250f9d865ce0ad3d51d45cad4 |