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

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.1
File Size Uploaded Provenance Actions
streambus-0.2.1.tar.gz 13.2 kB With provenance Details for streambus-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 21.7 kB

Release files / streambus-0.2.1.tar.gz

Download URL streambus-0.2.1.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e51d9a11eaaeb098b599dd0dec0553494b7847a9532d2443fa1465fef032f476
BLAKE2b-256 checksum
How to use checksums
86b0c7acddfad61e76f0e27c40d70ac1a20bb5c8d54bf63aedfe9e0dc4435b76
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 25, 2026.

Transparency log

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

Download URL streambus-0.2.1-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac29c816831f5a76d05d5de4ab166dcef3ade304110af456ee2fc696be42a494
BLAKE2b-256 checksum
How to use checksums
0a17d23a95d754c5827ca547e44bcfeca9f4fec79fda57629149c9fe2066ec32
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 25, 2026.

Transparency log

Security for streambus 0.2.1

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.1.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 25, 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