PL-EBS
Peach's Lightweight Event Bus Singleton
Low code, low dependency, simple implementation of an Event Bus
Events
Events are the messages that will be published to topics.
Events included in a events/ package at the root of the project are automatically imported to PL-EBS at start up. It is not a requirement that all Event definitions exist in one package but it is recommended as it makes the code cleaner and easier to manage. It is slighly more efficient as well since the penalty of dynamic class creation and registration are paid at initialization and not during run time.
from event_bus import event_message
# Event that uses the class name as the topic
@event_message
class MyEvent:
data: str
# Event that uses a specific topic name
@event_message(topic="custom.topic")
class AnotherEvent:
pass
Publish
Once an event is registered it can be used on the event bus. Events are published by calling the publish(topic: str, **kwargs) method. The key word arguments are used to populate the fields defined in the Event's class.
from event_bus import EventBus
EventBus().publish("MyEvent", data="Important Message")
Handlers
Unlike Events, handlers are not self-registered at initialization. Handlers can be registered by using the @event_handler decorator along with the register_handlers(obj: Any) method or calling EventBus().subscribe(topic: str, handler: Callable[BaseEvent])
Using decorators:
from event_bus import event_handler, register_handlers
class MyClass:
def __init__(self):
register_handlers(self)
@event_handler("MyEvent")
def handler(self, msg):
do_something(msg)
Subscribing to a topic directly:
from event_bus import EventBus
def handler(msg):
do_something(msg)
EventBus().subscribe(topic="MyEvent", handler=handler)
Metadata
Release files for pl-eb 0.1.0
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 |
|---|---|---|---|---|
| pl_eb-0.1.0.tar.gz | 5.7 kB | Without provenance | Details for pl_eb-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pl_eb-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pl_eb-0.1.0-py3-none-any.whl |
Total release size: 11.5 kB
Release files / pl_eb-0.1.0.tar.gz
| Download URL | pl_eb-0.1.0.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a5ec5858193c470dc8d6f3f344bc39e706d8dba50df3a3eedfefcbc9ef9304ec
|
|
BLAKE2b-256 checksum How to use checksums |
ef846f17d8a506a53ec1f272f4a2fb3f41f76a28d4453333557f099242ebd799
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / pl_eb-0.1.0-py3-none-any.whl
| Download URL | pl_eb-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
15bbf49b1a17eb550fc457986985ba6461bbf63ea762022cec3d49e74d025e54
|
|
BLAKE2b-256 checksum How to use checksums |
ab27cdbf64d655d24f77dba25183fe84bf9fed90d387e02484a6a2c4cd3a5655
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for pl-eb 0.1.0
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.