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.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


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

Uploaded Source

Built Distribution

yaeb-0.2.4-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: yaeb-0.2.4.tar.gz
  • Upload date:
  • Size: 3.8 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

Hashes for yaeb-0.2.4.tar.gz
Algorithm Hash digest
SHA256 a8887202e60c84b9392af745f34a459b25a7a2dc2ae06470009713f138ba7eb0
MD5 c977d414b39000b34640a5697836b19e
BLAKE2b-256 7baa84a8b06cca1f8f4ab3304c8347d057681fb9b0c072e0c6c22adcc71ec9cd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: yaeb-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 4.2 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

Hashes for yaeb-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a43385bfba8854534bc782a61947db6938f2b1c8fc22b9360a4a431ad12f6bf7
MD5 a0d6f1e1d16eb05c02d92cfec029c2a3
BLAKE2b-256 feb13e4ca0a06640fca12b11ba85e3960968da93cf298fa87a453d0f83e518e5

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