Bubus is an advanced, Pydantic-powered asynchronous event bus library for Python. It facilitates decoupled communication between components by allowing them to publish and subscribe to events. It's designed for modern Python applications, emphasizing type safety, performance, and robust error handling. The current version is 1.5.6, and it receives regular updates.
pip install bubusVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up an `EventBus`, define a `BaseEvent` with Pydantic, subscribe an asynchronous handler to it, and publish an event. It then shows how to wait for all handlers to complete and gracefully stop the bus.
Update any environment variables or configuration files that use `BUBUS_LOG_LEVEL` to `BUBUS_LOGGING_LEVEL`.
Adjust any error handling or `try...except` blocks around event `publish` calls to anticipate the direct propagation of handler-raised exceptions.
If you require return type validation, define your event classes like `class MyEvent(BaseEvent[str]): ...` and ensure handlers match `async def handler(event: MyEvent) -> str: ...`.
Always use the latest stable version of `bubus` when deploying in a multiprocessing context to leverage performance and stability improvements in semaphore management.
Correct the import statement to `from bubus import BubusBus` (assuming 'BubusBus' is the primary event bus class).
Ensure that the data (dictionary or keyword arguments) passed to the event constructor or during event creation strictly matches the Pydantic model's field types and constraints.
If calling from an `async` function, prepend `await` to the method call (e.g., `await bus.publish(event)`). If calling from a synchronous context, use `asyncio.run(bus.publish(event))` to execute the coroutine.
Modify the event handler function definition from `def my_handler(...)` to `async def my_handler(...)` to make it awaitable.