Skip to main content

URL routing for the websockets library.

Project description

Yrouter-websockets

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

Example

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

Project details


Release history Release notifications | RSS feed

This version

0.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yrouter-websockets-0.2.tar.gz (3.2 kB view details)

Uploaded Source

File details

Details for the file yrouter-websockets-0.2.tar.gz.

File metadata

  • Download URL: yrouter-websockets-0.2.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for yrouter-websockets-0.2.tar.gz
Algorithm Hash digest
SHA256 13ba9f6f51fb946f269aef9fc54307ee55b57fca74cb383b6723723cf8dd9d85
MD5 13870bb1b8b3816e3572f301f49e8b0f
BLAKE2b-256 1153ed9ec2267778f731b065e87bf26873f0892a31598c3171251124c7a99282

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page