RelayKit Tools
A tiny, dependency-free event bus for Python.
RelayKit Tools lets different parts of your application communicate through events without needing to know about each other.
Features
- Simple publish/subscribe API
- Decorator-based event handlers
- One-time event listeners
- Wildcard listeners for observing events
- Remove listeners individually or clear them all
- Zero runtime dependencies
- Type-annotated Python API
Installation
pip install relaykit-tools
Quick start
from relaykit_tools import EventBus
bus = EventBus()
def greet(name):
print(f"Hello, {name}!")
bus.on("user.joined", greet)
bus.emit("user.joined", "Alex")
# Output: Hello, Alex!
Use decorators
from relaykit_tools import EventBus
bus = EventBus()
@bus.on("order.created")
def process_order(order_id):
print(f"Processing order {order_id}")
bus.emit("order.created", 123)
One-time listeners
A one-time listener removes itself before its first invocation.
@bus.once("app.started")
def initialize():
print("Application initialized")
bus.emit("app.started")
bus.emit("app.started") # Does not invoke initialize again
Wildcard listeners
Listen to events regardless of their names. Wildcard handlers receive the event name as their first argument.
@bus.on("*")
def log_event(event_name, *args, **kwargs):
print(f"Event: {event_name}")
bus.emit("user.created", 42)
bus.emit("user.deleted", 42)
Remove listeners
def handle_message(message):
print(message)
bus.on("message", handle_message)
bus.off("message", handle_message)
# Remove every listener for one event
bus.off("message")
# Remove every listener for every event
bus.clear()
Inspect listeners
bus.listener_count("message") # Listeners for one event
bus.listener_count() # All registered listeners
Error handling
Handlers run in registration order. By default, if a handler raises an exception, the exception propagates to the caller and subsequent handlers are not invoked.
try:
bus.emit("task.started")
except Exception as exc:
print(f"Event handler failed: {exc}")
Limitations
- Event dispatch is synchronous.
- The event bus is not thread-safe.
- Handler exceptions stop the current dispatch.
- Event names are case-sensitive.
- Wildcard listeners use
"*"as their event name.
Requirements
Python 3.10 or newer.
License
MIT
Metadata
Release files for relaykit-tools 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| relaykit_tools-0.1.1.tar.gz | 4.0 kB | Without provenance | Details for relaykit_tools-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| relaykit_tools-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for relaykit_tools-0.1.1-py3-none-any.whl |
Total release size: 8.4 kB
Release files / relaykit_tools-0.1.1.tar.gz
| Download URL | relaykit_tools-0.1.1.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
69777362270e65fc0128714a68185a66a11f5bc0205561f507ceb2307e734342
|
|
BLAKE2b-256 checksum How to use checksums |
2495aee040332f018692404bdc8d3925090a8f7f62cf91d53c2c60ae34207261
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.2
|
Release files / relaykit_tools-0.1.1-py3-none-any.whl
| Download URL | relaykit_tools-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dd5836416d6c45dae4b49d51c85e4e3fe833030c3289596dde590b080fd8c303
|
|
BLAKE2b-256 checksum How to use checksums |
51dc7d9faee319e7a8659f7ec9ddcc3b2a82bc48dcc734ff2960b58c61c8ebcc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.2
|
Security for relaykit-tools 0.1.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.