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.2.0.tar.gz
(3.5 kB
view details)
Built Distribution
yaeb-0.2.0-py3-none-any.whl
(3.9 kB
view details)
File details
Details for the file yaeb-0.2.0.tar.gz
.
File metadata
- Download URL: yaeb-0.2.0.tar.gz
- Upload date:
- Size: 3.5 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 | d9fe48fb1ddaf119c37f7bfed85337bfbb4e3ec293c68dbbb0d3eabb214fe39a |
|
MD5 | 13a27b8c1589964aa80bed074eabc5d0 |
|
BLAKE2b-256 | 401f79bb0c775184edf06e7eb7a96f6f81cb67a30320de498520a3a396726830 |
File details
Details for the file yaeb-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: yaeb-0.2.0-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 | cfd5fab0136d7ab4474933ad20fb30b68ff0ece0d57ac8e4de424b451e77eb45 |
|
MD5 | 7c6d0d35df7009da1e0479c0d2a2a178 |
|
BLAKE2b-256 | a262c7d15d67c10318a8dad496f9bc8b38d720448056fdfa6d3646ebfeaf6566 |