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.3.tar.gz
(3.6 kB
view details)
Built Distribution
yaeb-0.2.3-py3-none-any.whl
(4.0 kB
view details)
File details
Details for the file yaeb-0.2.3.tar.gz
.
File metadata
- Download URL: yaeb-0.2.3.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 | 97f4d4684ebb4d7504a1f567fd239c6d90a49d62ece3e24a08737999cbe6e95d |
|
MD5 | 00955bc5f85b35bef1d82d0b15824fd5 |
|
BLAKE2b-256 | 421654be844120717a19982e2328d48cc2598468a53a9ed3b2d130c1376829ca |
File details
Details for the file yaeb-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: yaeb-0.2.3-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 | d90c797c357e75959056d433a0fac492f12d62dcc87f4f40f5638034170c19e0 |
|
MD5 | c0e2670eb856c66eb1e0243951a39001 |
|
BLAKE2b-256 | bf12b5ff2da4da6d8a53c8c1ac2b3b83b828ed39e240c365501146939736d6be |