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-1.0.0.tar.gz
(4.0 kB
view details)
Built Distribution
File details
Details for the file django_ws-1.0.0.tar.gz
.
File metadata
- Download URL: django_ws-1.0.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.10.3 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91e481110328cc2d06071d5e3ebaa9b9947343e7df119d70d21506072f7e575c |
|
MD5 | 61482156c4ef3a1adb6c666f37af76db |
|
BLAKE2b-256 | b8199ee006c3ee81c2e7f99eee3cc9ca2bda3880bb668105f79b6e93766c9710 |
File details
Details for the file django_ws-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: django_ws-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.10.3 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8e9a356bade4370a67f42329883247532496cd06f79f14a65c1b0c48fb81099 |
|
MD5 | ecdee9bc21c74203bd3357b4ca9a6dfd |
|
BLAKE2b-256 | 1e38157dfd70fce8a3231e8d5729060144b2bd6fb776979ff4af43982638078f |