跳转到主要内容

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 (3.2 kB 查看散列)

上传时间

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面