A simple typed event bus written in pure python
Project description
Yet another event bus - yaeb for short
A simple typed event bus written in pure python
Installation
Install yaeb with pip
pip install yaeb
Usage/Examples
from logging import info
from yaeb.bus import EventBus, NonPersistentEventHandlerRegistry
from yaeb.interface import Event, EventBusInterface, EventHandler
class UserCreated(Event):
user_id: int
def __init__(self, user_id: int) -> None:
self.user_id = user_id
class UserCreatedHandler(EventHandler[UserCreated]):
def handle_event(self, event: UserCreated, bus: EventBusInterface) -> None:
info('User with id=%d was created!', event.user_id)
if __name__ == '__main__':
bus = EventBus(event_handler_registry=NonPersistentEventHandlerRegistry())
bus.register(event_type=UserCreated, event_handler=UserCreatedHandler())
bus.emit(UserCreated(user_id=1)) # prints log message with created user id
Roadmap
- Add coroutines support
- Add some kind of multithreading support. Though it can be implemented by handlers themselves 🤔
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
yaeb-0.2.2.tar.gz
(3.6 kB
view details)
Built Distribution
yaeb-0.2.2-py3-none-any.whl
(4.0 kB
view details)
File details
Details for the file yaeb-0.2.2.tar.gz
.
File metadata
- Download URL: yaeb-0.2.2.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.6 Linux/5.15.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e23721a156a26ea50d87027fe4532a0200a4a70d22dc990e51aa34d048254b64 |
|
MD5 | 8aa4eb31eb158a7dad6eeb9c249e6fe1 |
|
BLAKE2b-256 | 42543c8fd619eefa8c85b532771059233831d38b46454c6938b49499f596c6a2 |
File details
Details for the file yaeb-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: yaeb-0.2.2-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.6 Linux/5.15.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf4a1be871aef8891926a740e0f4a1cc37dc1ef52e5cbdb8e02d68a7839268a1 |
|
MD5 | 386f7e7fc4512c2726d46fa981c5c009 |
|
BLAKE2b-256 | 18992b814ad91a4b5b42e4864b53fc4b79989f1a65d4f84c307fe1a39ebf9ed9 |