Pyventus is a modern and robust Python library for event-driven and reactive programming. It provides a comprehensive suite of tools to define, emit, manage, and orchestrate events with ease, using customizable event emitters and flexible responses. The current version is 0.8.0. The library is actively maintained with a regular release cadence, ensuring ongoing compatibility and feature enhancements.
pip install pyventusVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the basic event-driven usage of Pyventus. It defines an event handler using the `@EventLinker.on` decorator for a 'GreetEvent' and then emits this event using an `AsyncIOEventEmitter` instance. When the event is emitted, the `handle_greet_event` function is called, printing 'Hello, World!'.
Update import statements from `from pyventus import ...` to `from pyventus.events import ...`.
Remove inheritance from `Event` for custom event classes. Review and update any code that explicitly referenced `Event` class properties or methods.
Review `EventLinker` method calls and update them to use the new names, such as `EventLinker.get_registry()`.
If interacting with `EventEmitter`'s internal processing logic or `debug` flags, update method names and flag names accordingly.
Ensure `typing-extensions` is installed: `pip install typing-extensions`.
pip install pyventus
from pyventus import EventEmitter, Event
event_emitter.emit(MyEvent("Hello"))from pyventus import EventEmitter, Event
event_emitter = EventEmitter()
class MyEvent(Event):
def __init__(self, data: str):
self.data = data
@event_emitter.on(MyEvent)
def my_listener(event: MyEvent): # The 'event' parameter is crucial
print(f"Received event with data: {event.data}")
event_emitter.emit(MyEvent("Hello, Pyventus!"))