Keywords: event-bus, distributed, stream, processing, data, queue, kafka, python
pip install git+https://github.com/Airbase/eventbusk.gitfrom eventbusk import Event, EventBus
from dataclasses import dataclass
# create an app instance of the bus
bus = EventBus(broker="kafka://localhost:9092")
# define an event as a dataclass
@dataclass
class Foo(Event):
foo: int
# register the event to a single topic
bus.register_event("topic_foo", Foo)
# Define an method that receives that event
@bus.receive(event_type=Foo)
def process_a(event):
logger.info(f"Foo: {event}")
# Publish an event to the bus
foo = Foo(foo=1)
bus.send(foo)Set up the project locally:
git clone git@github.com:Airbase/eventbusk.git
cd eventbusk
uv sync --extra dev
pre-commit installYou will need a Confluent Kafka server locally via Docker by following https://docs.confluent.io/platform/current/platform-quickstart.html
There's an examples/docker-compose.yml that we can use to run a Kafka broker in a separate terminal window
cd examples
docker-compose upNow you can run the example project consumers. Ensure the topics in the example are created first.
# See examples/eventbus.py
uv run eventbusk worker -A eventbus:busYou can also publish a sample message:
uv run python
>>> from eventbus import bus, Fooey, Barzy
>>> bus.send(Fooey(foo_val="lorem ipsum"))
>>> bus.send(Barzey(bar_val="dolor sit amet"))After making code changes you can run some basic sanity checks as follows.
Run the tests:
uv run task testRun the linter:
uv run task ruff
uv run task pylintFormat the code:
uv run task formatRun type checks:
uv run task typecheckYou can also choose running pre-commit manually, which runs all all of the above, among other things.
uv run pre-commit run --all-files