SockJS-Channels
SockJS-Channels is a server-side implementation of the SockJS protocol for the Django Channels and was inspired by the SockJS-aiohttp project. SockJS-Channels interface is implemented as a ASGI routing, it runs inside a ASGI application rather than ASGI server. Its possible to create any number of different sockjs routings, ie /sockjs/* or /chat-sockjs/*. You can provide different session implementation and management for each sockjs routing.
Requirements
- Python 3.6+
- Django 3.2+
- Channels 3.0.0+
Installation
$ pip install sockjs-channels
ASGI Routing
Here’s an example of asgi.py might looks like:
import os
from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application
from django.urls import re_path
from sockjs import make_routing
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'chat.settings')
# Initialize Django ASGI application early to ensure the AppRegistry
# is populated before importing code that may import ORM models.
django_asgi_app = get_asgi_application()
from chat.views import chat_msg_handler
routing = make_routing(chat_msg_handler, name='chat')
# Add django's url routing
routing.http.append(re_path(r'', django_asgi_app))
application = ProtocolTypeRouter({
'http': URLRouter([
*routing.http
]),
'websocket': URLRouter([
*routing.websocket
])
})
Supported Transports
- websocket
- xhr-streaming
- xhr-polling
- iframe-xhr-polling
- iframe-eventsource
- iframe-htmlfile
- jsonp-polling
Examples
You can find a simple chat example in the sockjs-channels repository at github.
https://github.com/iTraceur/sockjs-channels/tree/main/examples/chat
License
sockjs-channels is offered under the MIT license.
Test Coverage
Name Stmts Miss Branch BrPart Cover
---------------------------------------------------------------------
sockjs/__init__.py 15 0 0 0 100%
sockjs/constants.py 5 0 0 0 100%
sockjs/exceptions.py 3 0 6 0 100%
sockjs/protocol.py 36 0 0 0 100%
sockjs/routing.py 116 15 30 10 83%
sockjs/session.py 305 6 118 12 96%
sockjs/transports/__init__.py 10 0 0 0 100%
sockjs/transports/base.py 139 17 40 9 84%
sockjs/transports/eventsource.py 18 0 6 1 96%
sockjs/transports/htmlfile.py 34 0 10 1 98%
sockjs/transports/jsonp.py 50 0 16 0 100%
sockjs/transports/rawwebsocket.py 51 1 16 2 96%
sockjs/transports/utils.py 26 3 6 3 81%
sockjs/transports/websocket.py 63 2 14 1 96%
sockjs/transports/xhr.py 15 0 4 0 100%
sockjs/transports/xhrsend.py 29 0 8 0 100%
sockjs/transports/xhrstreaming.py 16 0 4 0 100%
---------------------------------------------------------------------
TOTAL 931 44 278 39 93%
Changelog
0.1.2 / 2022-05-23
- Fix: scope lost in xhr_send and jsonp_send transports after session released.
- Optimize: heartbeat frame messages do not update session's expires.
- Optimize: notify frontend when session is to be GC'd.
0.1.1 / 2022-04-09
- Update version, setup.py and README.md
- Update tests
- Update websocket transport
- Adjust and optimize transports
- Update examples
0.1.0 / 2022-03-27
- First implementation steps.
- Initial commit
Metadata
Release files for sockjs-channels 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sockjs-channels-0.1.2.tar.gz | 16.0 kB | Without provenance | Details for sockjs-channels-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sockjs_channels-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for sockjs_channels-0.1.2-py3-none-any.whl |
Total release size: 36.6 kB
Release files / sockjs-channels-0.1.2.tar.gz
| Download URL | sockjs-channels-0.1.2.tar.gz |
|---|---|
| Size | 16.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4e47e40fb4fc0d831bb3d07782bded32f300c712ea94e7e7d436e06920622949
|
|
BLAKE2b-256 checksum How to use checksums |
78870306f8c64ced18d57f116efb7d74b413c8824dce26024e874e1aed19f88c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.4
|
Release files / sockjs_channels-0.1.2-py3-none-any.whl
| Download URL | sockjs_channels-0.1.2-py3-none-any.whl |
|---|---|
| Size | 20.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
93cd9930e5ec9d80d2bda16921c37dc846e03e4b88063c06b39d265ceb135677
|
|
BLAKE2b-256 checksum How to use checksums |
1c4776e24195f75e259f49337bc90871ce131fbc6b8f2948929f3512204d624d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.4
|
Security for sockjs-channels 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.