Skip to main content

streambus

PyPI version PyPI downloads Python License Release Tests

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

publisher = EventPublisher(
    stream="orders:events",
    config=RedisConfig(url="redis://localhost:6379"),
)

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

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,
    config=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. A message published to a stream reaches every group exactly once.

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
    config=RedisConfig(...),  # required
    consumer=None,            # defaults to "{group}-1"
    batch_size=10,
    block_ms=5000,
    retry_delay=3.0,
)

EventPublisher

EventPublisher(
    stream="stream:name",    # required
    config=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.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for streambus 0.2.0
File Size Uploaded Provenance Actions
streambus-0.2.0.tar.gz 12.9 kB With provenance Details for streambus-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for streambus 0.2.0
File Interpreter ABI Platform Actions
streambus-0.2.0-py3-none-any.whl Python 3 none any Details for streambus-0.2.0-py3-none-any.whl

Total release size: 21.4 kB

Release files / streambus-0.2.0.tar.gz

Download URL streambus-0.2.0.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3f1860baf3364017dbaa79df47f972c9aab3a9c314936facae84bf729ccf8f52
BLAKE2b-256 checksum
How to use checksums
0456a47d943f512fa8e5e4ace1dfeb92fdb5d5a8a4b01ab24b618d8bc40dcac6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 24, 2026.

Transparency log

Release files / streambus-0.2.0-py3-none-any.whl

Download URL streambus-0.2.0-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7309dd9bc744104246b3ad7894c694424f86a2cd9ec8908234bc9ef6a512c390
BLAKE2b-256 checksum
How to use checksums
49721061ecc131d568a89dd096342a5b9bd28a967f4fe0b225b81ece7bdc5299
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 24, 2026.

Transparency log

Security for streambus 0.2.0

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.

Select from 2 files

Attestation for streambus-0.2.0.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 Aug 24, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page