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):
Clientuses 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
Publishing to PyPI
-
Install build tools
pip install build twine
-
Build the package
python -m build
This creates
dist/sessionbus-<version>.tar.gzanddist/*.whl. -
Upload to PyPI
TWINE_USERNAME=__token__ TWINE_PASSWORD=... twine upload dist/*
To try Test PyPI first:
twine upload --repository testpypi dist/* -
After upload: users can install with
pip install sessionbus.
License
sessionbus is released under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sessionbus-0.1.0.tar.gz.
File metadata
- Download URL: sessionbus-0.1.0.tar.gz
- Upload date:
- Size: 22.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f81aa8cab22fb3c5ff499da3b94b3d519ea02b4eb9cd9a02457a40ac0fafc2e6
|
|
| MD5 |
976dc0c4194fbcf89c9ad0093c4e9743
|
|
| BLAKE2b-256 |
e0a9bfe996330a26f004a8b2394d2f290514fc02d9a6c320b87f5f3f052f612b
|
File details
Details for the file sessionbus-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sessionbus-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e12a05e9c8b6b833e6809846d61764d8fd336d3b12e699cf5e2d46fa14512e1
|
|
| MD5 |
8c5c38fafeb63f98f7b7922b41928f46
|
|
| BLAKE2b-256 |
29811cb9feccd3029727b2187e54e898580e32a4fcab61a9e15006ecdf6a983c
|