Skip to content

Tijani-Dia/yrouter-websockets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yrouter-websockets

yrouter-websockets is a URL routing package for the websockets library. It's built on top of yrouter.

Example

import asyncio

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())

Installation

yrouter-websockets requires Python>=3.9. You can install it from Pypi:

pip install yrouter-websockets

About

A URL routing package for the websockets library.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published