Skip to main content

Rooms, broadcast, and presence for WebSocket apps behind a small async API.

Project description

kasper-socket

Rooms, broadcast, and presence for WebSocket apps - behind a small async API. Framework-agnostic: works with FastAPI / Starlette / the websockets library. Any object with an async send(str) is a valid socket.

pip install kasper-socket
from kasper_socket import SocketHub

hub = SocketHub()

conn = await hub.connect(ws, user_id="u1", rooms=["case-42"])
await hub.broadcast("case-42", {"type": "edit", "field": "status"})
await hub.presence("case-42")     # -> ["u1", "u2"]
await hub.disconnect(conn)

@hub.on("edit")
async def handle(conn, msg):
    ...
await hub.dispatch(conn, {"type": "edit", "field": "status"})

Notes

  • Single node broadcast is an in-process room lookup.
  • Presence is tracked per room and emitted as a sorted member list.
  • A Redis pub/sub backend (for multi-node broadcast across server instances) is the planned [redis] extra.

MIT licensed.

Project details


Download files

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

Source Distribution

kasper_socket-0.1.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kasper_socket-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file kasper_socket-0.1.0.tar.gz.

File metadata

  • Download URL: kasper_socket-0.1.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for kasper_socket-0.1.0.tar.gz
Algorithm Hash digest
SHA256 67acd318940ef7b414b40e80d80e00a34bade288097691bcc435be1e294699ec
MD5 ec1c2ff1e5f3b89f75a33870f0a01f20
BLAKE2b-256 e4579a2727935e884e0bf1c7afb5158d17afefbc14e8bcd7c5de70adc27e90fa

See more details on using hashes here.

File details

Details for the file kasper_socket-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: kasper_socket-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for kasper_socket-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5b42495c350db156242cf1b809797abb4cea4b2c7bacbc52d38624c903a60787
MD5 2904775dc5910cded6952223e6c36422
BLAKE2b-256 22a5718475e6203938cb0bc91442a38d9b1e06314aa7ca98048e76e5742aa58f

See more details on using hashes here.

Supported by

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