How markkorput/pyevento works
Project type and purpose
• pyevento (the “evento” Python package) is an open-source library that implements the Observer pattern in both synchronous and asynchronous styles.
• Its purpose is to let client code define and fire events, subscribe and unsubscribe handlers easily, and decorate methods to become multi-argument events.
File structure
• Top-level module: evento/
• base.py – core abstractions and shared utilities
• event.py – the synchronous Event[T] class
• async_event.py – the AsyncEvent[T] class for Python async/await
• decorators.py – @event and @async_event decorators (multi-arg support)
• signature.py – internal machinery for handling arbitrary signatures
• __init__.py – public API imports and type aliases
• examples/ – sample usage scripts (basic, async, signature)
• tests/ – unit tests per module
• config files – CI (Travis), linting (mypy), packaging (pyproject.toml, setup.cfg), coverage
Key insights from README
• Features:
• Simple subscribe/unsubscribe for single-arg events (generic)
• Async support with awaitable firing
• Decorators for multi-argument events, preserving the original function call
• Usage patterns:
• Client creates Event[T] or AsyncEvent[T]
• Client subscribes handlers (+=, .add, .append)
• Client fires events (event(...) or await event(...))
• Client unsubscribes (-= or .remove or returned cleanup callable)
Main components
• Public API layer (evento/__init__.py)
• Core classes:
• Event[T] (sync dispatcher)
• AsyncEvent[T] (async dispatcher)
• Decorator layer:
• event decorator (sync multi-arg)
• async_event decorator (async multi-arg)
• Subscription mechanism:
• Internal subscriber registry (list of callables)
• /append and remove methods, operator overloads (__iadd__, __isub__)
• Dispatch mechanism:
• Event.__call__ → iterate subscribers → invoke handlers
• AsyncEvent.__call__/fire → await each subscriber
• Signature handling (signature.py)
• Wraps decorated methods, inspects and forwards args/kwargs
Relationships and data flow
• Client code → instantiates Event or AsyncEvent
• Client code ↔ (operator overloads) subscribes/unsubscribes handlers
• Firing an event:
a) Sync: client calls event(data) → Event.__call__ → for each handler: handler(data)
b) Async: client awaits event(data) → AsyncEvent.__call__ → await handler(data) → collect results/return value
• Decorator usage: method definition is replaced by an Event/AsyncEvent instance under the hood, but still calls the original function.
Architectural patterns and principles
• Observer pattern (publish–subscribe)
• Decorator pattern (wrapping methods to become events)
• Single responsibility: each module focuses on one aspect (sync vs async vs decoration)
• Generic typing (PEP 484) for type safety
Detail
• Generic type parameter T flowing from instantiation down to handler signatures
• Both single-arg flow and multi-arg decorator flow in separate sub-flows