WebRockets — это высокопроизводительный WebSocket-сервер для Python с нативной поддержкой Django. Ядро написано на Rust (PyO3 + axum + fastwebsockets) для максимальной скорости — до 10x быстрее Daphne в бенчмарках.
runwebsockets.from webrockets import WebsocketServer
server = WebsocketServer(host="0.0.0.0", port=8080)
echo = server.create_route("ws/echo/", "echo")
@echo.connect("before")
def on_connect(conn): print(f"Connected: {conn.path}")
@echo.receive
def on_message(conn, data): conn.send(f"You said: {data}")
server.start()
Django (websockets.py в app):
from webrockets.django import server
from webrockets.django.auth import SessionAuthentication
chat = server.create_route("ws/chat/", "chat", authentication_classes=[SessionAuthentication()])
@chat.connect("before")
def on_connect(conn): print(f"User {conn.user} joined")
@chat.receive(match=Match("type", "message"), schema=ChatMessage)
def on_message(conn, data: ChatMessage): conn.broadcast([data.room], data.content)
# Запуск: python manage.py runwebsockets
pip install webrockets[django,schema].#WebRockets #WebSocket #Django #Rust #Python #Async #HighPerformance #WebDev #OpenSource
https://github.com/ploMP4/webrockets
Please open Telegram to view this post
VIEW IN TELEGRAM
GitHub
GitHub - ploMP4/webrockets: High-performance rust powered websockets for python
High-performance rust powered websockets for python - ploMP4/webrockets
2👍6🔥2 2