WebSockets库的URL路由。
项目描述
Yrouter-websockets
yrouter-websokets
是一个用于 websockets
库的URL路由包。它是基于 yrouter
构建的。
示例
import asyncio
import http
import websockets
from yrouter import route
from yrouter_websockets import router
async def home(ws):
await ws.send("In home")
async def hello_user(ws, username):
await ws.send(f"Hello {username}")
async def channel(ws, channel_id):
# Do some stuff with channel_id
routes = (
route("/", home),
route("hello/<str:username>/", hello_user),
route("channels/<int:channel_id>", channel),
)
async def main():
async with websockets.serve(router(routes), "localhost", 8765):
await asyncio.Future()
if __name__ == "__main__":
asyncio.run(main())
项目详细信息
关闭
yrouter-websockets-0.2.tar.gz的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | 13ba9f6f51fb946f269aef9fc54307ee55b57fca74cb383b6723723cf8dd9d85 |
|
MD5 | 13870bb1b8b3816e3572f301f49e8b0f |
|
BLAKE2b-256 | 1153ed9ec2267778f731b065e87bf26873f0892a31598c3171251124c7a99282 |