Events (pyeve)
raw JSON → 0.5 verified Tue May 12 auth: no python install: verified quickstart: verified maintenance
The 'events' library for Python, currently at version 0.5, aims to bring the elegance of C# EventHandler to Python. It provides a simple, lightweight mechanism for event subscription and firing, encapsulating the core functionality for attaching and invoking callback functions (event handlers) in sequence, thus facilitating event-driven programming patterns in a straightforward manner. The library is considered mature and stable, with its last release in July 2023, and sees infrequent updates.
pip install events Common errors
error ModuleNotFoundError: No module named 'events' ↓
cause The 'events' package has not been installed in your Python environment or there is a typo in the import statement.
fix
Install the library using pip:
pip install Events. Ensure your import statement is from events import Event. error AttributeError: 'Event' object has no attribute '...' (e.g., 'name', 'type') ↓
cause The base `events.Event` object does not automatically possess arbitrary attributes like 'name' or 'type'. Event data is typically accessed via `event.sender`, `event.args` (for positional arguments), or `event.kwargs` (for keyword arguments).
fix
Access event data using
event.sender, event.args, or event.kwargs. If you intend to pass named data, use keyword arguments when firing the event and access them via event.kwargs['your_key']. error TypeError: handler_function() missing X required positional argument: 'Y' ↓
cause An event handler function was subscribed with a signature (parameters) that does not match the arguments provided when the event is fired.
fix
Ensure that the event handler function's parameters (
sender, *args, **kwargs) correctly correspond to the arguments passed to event.fire(sender, *args, **kwargs). Warnings
gotcha The `Events()` instance holds strong references to subscribed callback functions. If an event handler is a method of an object, and the `Events` instance outlives that object, it can prevent the object from being garbage collected, leading to memory leaks. Always explicitly unsubscribe handlers using `-=` when they are no longer needed, especially for object methods. ↓
fix Ensure `event_instance.event_name -= handler_function` is called when the handler is no longer required or the associated object is being disposed of. Consider weak references for advanced scenarios if manual unsubscription is problematic.
gotcha By default, `Events` instances do not predefine event names. This means you can subscribe to and fire any arbitrary event name (e.g., `events.on_typo`). This flexibility can lead to subtle bugs due to typos in event names that might go unnoticed. For stricter validation, you can predefine events. ↓
fix To enforce predefined events, subclass `Events` and list event names in the class definition, or pass an iterator of event names to the `Events` constructor. Attempts to subscribe to or fire an undefined event will then raise an `EventsException`.
gotcha The package name 'events' is highly generic. There are several other Python libraries and standard library modules (e.g., `eventsourcing`, `pyventus`, `python-dispatch`, `threading.Event`) that deal with event-related patterns. Ensure you are installing and using `pyeve/events` if this is your intended library. ↓
fix Always import explicitly (e.g., `from events import Events`) and check the `events.__file__` to confirm you're using the correct package. Refer to documentation specific to `github.com/pyeve/events`.
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.00s 17.8M
3.10 slim (glibc) - - 0.00s 18M
3.11 alpine (musl) - - 0.00s 19.7M
3.11 slim (glibc) - - 0.00s 20M
3.12 alpine (musl) - - 0.00s 11.5M
3.12 slim (glibc) - - 0.00s 12M
3.13 alpine (musl) - - 0.00s 11.2M
3.13 slim (glibc) - - 0.00s 12M
3.9 alpine (musl) - - 0.00s 17.3M
3.9 slim (glibc) - - 0.00s 18M
Imports
- Events
from events import Events
Quickstart verified last tested: 2026-04-23
from events import Events
def my_event_handler(reason, data=None):
print(f"Event fired: {reason}")
if data:
print(f" Data: {data}")
# Create an Events instance
app_events = Events()
# Subscribe a handler to an event named 'on_change'
app_events.on_change += my_event_handler
# Fire the 'on_change' event
print("Firing event: 'initial change'")
app_events.on_change("initial change", data={"user": "admin"})
# Subscribe another handler to the same event
def another_handler(reason):
print(f"Another handler received: {reason}")
app_events.on_change += another_handler
# Fire the event again
print("\nFiring event again: 'second change'")
app_events.on_change("second change")
# Unsubscribe a handler
app_events.on_change -= my_event_handler
# Fire the event one last time (only 'another_handler' will be invoked)
print("\nFiring event after unsubscription: 'final change'")
app_events.on_change("final change")