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.1.tar.gz
(3.6 kB
view details)
Built Distribution
yaeb-0.2.1-py3-none-any.whl
(3.9 kB
view details)
File details
Details for the file yaeb-0.2.1.tar.gz
.
File metadata
- Download URL: yaeb-0.2.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.5 Linux/5.18.16-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83ad5aa78d1f6a2cf70c0b6653f2b0b7836aa0f44dff67545327ffed15141e25 |
|
MD5 | fa50b40bc34defdffe3f8ef868ccae86 |
|
BLAKE2b-256 | 9b72b54b4b1e881372a4deb20ad668eb336470f0237e66b0808e55d79527b8a7 |
File details
Details for the file yaeb-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: yaeb-0.2.1-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.5 Linux/5.18.16-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f9dcf54b1b40499dc6fcce424c04e82c45e59f223baf67dd5603e008a33fd26 |
|
MD5 | 6e4a1d643c8240c10590bcb6ab49895c |
|
BLAKE2b-256 | 106bcf548d460353903c631df277f1f82a006b7df489e3899750b282e06dfaac |