Skip to main content

Session bus Python package

Project description

sessionbus

sessionbus is a lightweight WebSocket message bus for Python. Clients subscribe by (user_id, session_id); the server pushes payloads to all subscribers for that key. When disconnects, subscriber messages go into an outbox (in-memory or PostgreSQL) and are delivered when a client reconnects.

Key features

  • Simple subscription model: One key per conversation: (user_id, session_id). Subscribe, send, and receive on that key.
  • Outbox when offline: If no client is connected for a key, payloads are queued (memory + optional Postgres). On the next subscribe, the server drains the outbox and sends them.
  • Connection pool (client): Client uses a pool of WebSockets; hash-based routing spreads keys across connections. Reconnect and re-subscribe are handled per slot.

Installation

From the project root

pip install -e .

With dev dependencies (pytest, pytest-asyncio, pytest-cov). See [project.optional-dependencies] in pyproject.toml:

pip install -e ".[dev]"

Optional: Postgres outbox backend:

pip install -e ".[postgres]"

Usage

Server: start the bus and push to a key:

from sessionbus import Server

server = Server(host="127.0.0.1", port=8765)
await server.start()

# Later: push to all subscribers of (user_id, session_id)
await server.push("user-1", "session-abc", payload)

For a runnable server script, see examples/run_server.py.

Client: connect, subscribe to the keys you need, then send and receive:

from sessionbus import Client

client = Client("ws://127.0.0.1:8765", pool_size=4)
await client.connect()
await client.subscribe("user-1", "session-abc")

await client.send("Hello", user_id="user-1", session_id="session-abc")
payload = await client.recv("user-1", "session-abc", timeout=5.0)

Development

Run tests:

pytest

License

sessionbus is released under the MIT License.

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

sessionbus-0.1.1.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

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

sessionbus-0.1.1-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file sessionbus-0.1.1.tar.gz.

File metadata

  • Download URL: sessionbus-0.1.1.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for sessionbus-0.1.1.tar.gz
Algorithm Hash digest
SHA256 556d03641543e791adcb55cff99c6c9995ec1c0aedd7477c881f520afd5aaec3
MD5 ab98f3a19a2bbec8d237fc955ba9a153
BLAKE2b-256 43674c2d745e1675998274bf741ca781ad2197d4bfdca3fef6a4dc0e785eb22a

See more details on using hashes here.

File details

Details for the file sessionbus-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sessionbus-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for sessionbus-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e6b86d6b85f20fb6292561c36227a178496d236bf92a1807e2b62ced4c2f87fa
MD5 a5f076eaf52e80ed67f7be9eeaa7304f
BLAKE2b-256 40ccab390580ff8d51f830930904b5b54c5c5be53142f98b816f93200b337e2c

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