Skip to main content

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.base.bus import BaseEventBus
from yaeb.base.events import BaseEvent
from yaeb.base.handlers import BaseSyncEventHandler
from yaeb.bus import DictEventHandlerRegistry, EventBus


class UserCreated(BaseEvent):
    user_id: int

    def __init__(self, user_id: int) -> None:
        self.user_id = user_id


class UserCreatedHandler(BaseSyncEventHandler[UserCreated]):
    def handle_event(self, event: UserCreated, bus: BaseEventBus) -> None:
        info('User with id=%d was created!', event.user_id)


if __name__ == '__main__':
    bus = EventBus(event_handler_registry=DictEventHandlerRegistry())
    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 - Added BaseAsyncEventHandler
  • Add some kind of multithreading support. Though it can be implemented by handlers themselves 🤔 - Added BaseExecutorEventHandler

Project details


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.4.2.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

yaeb-0.4.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file yaeb-0.4.2.tar.gz.

File metadata

  • Download URL: yaeb-0.4.2.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.10.6 Linux/5.15.0-1019-azure

File hashes

Hashes for yaeb-0.4.2.tar.gz
Algorithm Hash digest
SHA256 e5516ad69ed9b8d09b25c2f715fe9dfda84ad34d3bb045b718377cafb8398599
MD5 13abe35e199cd4a53532b38a383227c5
BLAKE2b-256 cfdb271c486dbb865995aa9bc16172ab3886cee0034c00e1800657e7f1521e3a

See more details on using hashes here.

File details

Details for the file yaeb-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: yaeb-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.10.6 Linux/5.15.0-1019-azure

File hashes

Hashes for yaeb-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6a71f4b08be9346482d6c3bd71b2bb80bdb7484feee255c91e350cc940f8fe01
MD5 76d4ef35aee41937dbc5a5135d9695e2
BLAKE2b-256 f6404af79ec06d5c0b341eb89ed5557ec1efe84fe2d75456dd87da1adf301941

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page