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 Event, EventBus, 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: EventBus) -> None:
info('User with id=%d was created!', event.user_id)
if __name__ == '__main__':
bus = EventBus()
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.1.2.tar.gz
(3.1 kB
view details)
Built Distribution
yaeb-0.1.2-py3-none-any.whl
(3.1 kB
view details)
File details
Details for the file yaeb-0.1.2.tar.gz
.
File metadata
- Download URL: yaeb-0.1.2.tar.gz
- Upload date:
- Size: 3.1 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 | 660a8f8e6421206035846e6bc1cbbef2bbd9c518b1c19ca1815dd0640eb66a5c |
|
MD5 | acfb38420c008d7d207b2cd33c44cfc5 |
|
BLAKE2b-256 | ae9f02f965f795dfa399331ebaf0998366082a6dc489d202e305b7260f2f5a19 |
File details
Details for the file yaeb-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: yaeb-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.1 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 | ae41096d0e5f5524602c26ac9e77ac18538f86730f03adb7dab1ddc6055bcb8d |
|
MD5 | 9700f2340ef66dedb8852ddf89396830 |
|
BLAKE2b-256 | 0db915f37f81d3a2e2475a7dd3dd97cabd447e84f19c146670ed33b3c184c7e8 |