Skip to main content

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) or order.** (all remaining) and get every matching event — with the concrete topic on event.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_error handlers and a dead_letters log.
  • 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

larzbus-0.1.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

larzbus-0.1.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

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

Hashes for larzbus-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b7c6931e16e08d30d586fda4f510b019785a9a18575e12d6b93c14ea964ca660
MD5 50ffaf98658e2ee11a11da686aaa979b
BLAKE2b-256 f564171e7745a41362906fc4b194e58b8481b244a3955a7c9f104a58c7a2818c

See more details on using hashes here.

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

Hashes for larzbus-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a31bc607ab84121849812c342783b8ed5eab1fabb4745a48a3b847282ccb3dcc
MD5 a2b7ee21b4da71d42ef2d01ae9b74ee8
BLAKE2b-256 7a44726024dd847c02c1c37347e6b6e112fda5a639fd056585cd28908a26a43f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

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