streambus
Lightweight event bus over Redis Streams. Define typed events, publish from one service, consume in others without boilerplate or framework dependencies.
Install
pip install streambus
uv add streambus
Quick start
Define an event:
from dataclasses import dataclass
from streambus import StreamBusEvent
@dataclass(kw_only=True)
class OrderCreated(StreamBusEvent):
order_id: str
customer_id: str
total: str
Publish it:
from streambus import EventPublisher, RedisConfig, RedisStreamsTransport
transport = RedisStreamsTransport(RedisConfig(url="redis://localhost:6379"))
publisher = EventPublisher(stream="orders:events", transport=transport)
publisher.publish(
OrderCreated(
event_type="order.created",
order_id="ord_123",
customer_id="cust_456",
total="99.90",
)
)
Consume it:
from streambus import EventListener, RedisConfig, RedisStreamsTransport
def handle_order(event: OrderCreated) -> None:
print(f"New order {event.order_id}: total {event.total}")
EventListener(
stream="orders:events",
group="notifications",
handler=handle_order,
event_class=OrderCreated,
transport=RedisStreamsTransport(RedisConfig(url="redis://localhost:6379")),
).run()
How it works
streambus uses Redis Streams for transport: persistent storage, consumer groups, and at-least-once delivery. The library manages group creation, the blocking read loop, message acknowledgement, and automatic reconnection on connection loss.
Each consumer group processes events independently. Delivery is at least once: unacknowledged messages can be redelivered, so handlers must be idempotent. The listener reclaims idle pending entries using Redis XAUTOCLAIM before reading new entries (Redis 6.2+ required).
Events
All events extend StreamBusEvent:
| Field | Type | Required | Notes |
|---|---|---|---|
event_type |
str |
yes | Identifies the event. Convention: noun.verb |
occurred_at |
str |
no | ISO 8601 timestamp. Auto-set on creation. |
Subclasses declare only the fields they need. Unknown fields arriving from the stream are silently discarded — each consumer maps what it uses, nothing more.
Both StreamBusEvent and its subclasses must use @dataclass(kw_only=True). This is required: the base class has a field with a default (occurred_at), and kw_only=True prevents the ordering conflict that would otherwise block subclasses from adding required fields.
Configuration
RedisConfig
RedisConfig(
url="redis://localhost:6379", # required
socket_timeout=None, # None = no timeout (correct for blocking reads)
socket_connect_timeout=5.0, # seconds to wait on initial connect
)
EventListener
EventListener(
stream="stream:name", # required
group="consumer-group", # required
handler=my_handler, # required — callable(event) -> None
event_class=MyEvent, # required — must subclass StreamBusEvent
transport=RedisStreamsTransport(RedisConfig(...)), # required
consumer=None, # defaults to "{group}-1"
batch_size=10,
block_ms=5000,
retry_delay=3.0,
pending_idle_ms=60000, # minimum idle time before retrying pending entries
)
EventPublisher
EventPublisher(
stream="stream:name", # required
transport=RedisStreamsTransport(RedisConfig(...)), # required
)
Exceptions
| Exception | When |
|---|---|
ConfigurationError |
Invalid or missing parameters at construction time |
EventValidationError |
publish() receives a non-StreamBusEvent or empty event_type |
StreambusError |
Base class for all streambus exceptions |
Development
git clone https://github.com/jmeiracorbal/streambus
cd streambus
uv sync --group dev
uv run pytest tests/ -v
Run the example (requires Docker):
cd example
docker compose up -d # start Redis
uv sync
uv run python consume.py # terminal 1
uv run python publish.py # terminal 2
License
MIT
Metadata
Release files for streambus 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| streambus-0.2.2.tar.gz | 14.6 kB | With provenance | Details for streambus-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| streambus-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for streambus-0.2.2-py3-none-any.whl |
Total release size: 23.6 kB
Release files / streambus-0.2.2.tar.gz
| Download URL | streambus-0.2.2.tar.gz |
|---|---|
| Size | 14.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dfa99a6cd846282bf348fb0defc1afefaf9d17ef96b7ed78937e0eb954ae0e48
|
|
BLAKE2b-256 checksum How to use checksums |
204d170afba4d658c3ea4d076888b821fb9fe32364a1b2a85d8ed5676be1b162
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logRelease files / streambus-0.2.2-py3-none-any.whl
| Download URL | streambus-0.2.2-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4e157d957d2c6a1c7bb971379de5adce5c4ef468e9077119c64d6892390736d7
|
|
BLAKE2b-256 checksum How to use checksums |
a1e66267bb9b07ff11159b1250a7fd210e9d943df449882b411e04302e2c97c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logSecurity for streambus 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for streambus-0.2.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.