larzbus
An in-process pub/sub event bus. Pure Python, zero dependencies.
Decouple your app: publishers announce that something happened, subscribers react, and neither knows about the other — with three things ad-hoc callback lists lack.
from larzbus import EventBus
bus = EventBus()
@bus.on("user.*")
def audit(event):
print(event.topic, event.data)
bus.publish("user.created", {"id": 42}) # audit sees "user.created"
What makes it different
- Wildcard topics. Subscribe to
user.*(one segment) ororder.**(all remaining) and get every matching event — with the concrete topic onevent.topic. - Async delivery when you want it.
bus.publish(topic, data, async_=True)runs handlers on a background thread, so one slow subscriber never blocks the publisher. - Dead-letter path. A handler that raises doesn't take down the publish — the
other handlers still run, and the event + exception go to your
on_errorhandlers and adead_letterslog. - Zero dependencies, thread-safe.
Install
pip install larzbus
Usage
from larzbus import EventBus
bus = EventBus()
# subscribe (decorator or direct); wildcards allowed
@bus.on("order.*")
def on_order(event):
...
sub = bus.subscribe("payment.completed", handler)
bus.once("startup", run_once) # auto-unsubscribes after first delivery
sub.unsubscribe()
# publish
results = bus.publish("order.created", {"id": 1}) # list of handler returns
bus.publish("email.queued", payload, async_=True) # non-blocking
# dead-letter
@bus.on_error
def failed(topic, event, exc):
log.warning("handler failed on %s: %s", topic, exc)
bus.dead_letters # [(topic, event, exception), ...]
Wildcards
| pattern | matches |
|---|---|
user.created |
exactly that topic |
user.* |
user.created, user.deleted (one more segment) |
order.** |
order.created, order.item.added, … (any depth) |
Tests
python -m unittest discover -s tests -v # 17 tests, zero deps
The Larz stack
Pure-Python, zero-dependency building blocks: larz · larzchain · larzmoney · larzcrypt · larzdb · larzagent · larzchart · larzmark · larztask · larzvault · larzvm · larzcache · larzvalidate · larzid · larzrpc · larzstate · larzhttp · larzconf · larzcron · larzlimit · larzlog · larzcli · larzretry · larztime · larzpdf · larzpack · larztemplate · larzcolor · larztable · larzjson · larzbus
License
MIT © larz-scripter
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file larzbus-0.1.0.tar.gz.
File metadata
- Download URL: larzbus-0.1.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7c6931e16e08d30d586fda4f510b019785a9a18575e12d6b93c14ea964ca660
|
|
| MD5 |
50ffaf98658e2ee11a11da686aaa979b
|
|
| BLAKE2b-256 |
f564171e7745a41362906fc4b194e58b8481b244a3955a7c9f104a58c7a2818c
|
File details
Details for the file larzbus-0.1.0-py3-none-any.whl.
File metadata
- Download URL: larzbus-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a31bc607ab84121849812c342783b8ed5eab1fabb4745a48a3b847282ccb3dcc
|
|
| MD5 |
a2b7ee21b4da71d42ef2d01ae9b74ee8
|
|
| BLAKE2b-256 |
7a44726024dd847c02c1c37347e6b6e112fda5a639fd056585cd28908a26a43f
|