Registered Event Listener (rel)

raw JSON →
0.4.9.26 verified Mon Apr 27 auth: no python

Rel is a lightweight (0.4.9.26) event/observer pattern library for Python that implements the standard pyevent interface without external dependencies. It provides a simple publish-subscribe mechanism with event registration, firing, and listener management. The library is API-stable with infrequent releases.

pip install rel
error AttributeError: module 'rel' has no attribute 'event'
cause Attempting to import from rel.event which does not exist as a submodule.
fix
Use: from rel import EventHandler (or simply import rel and use rel.add/fire).
error NameError: name 'add' is not defined
cause Importing incorrectly: from rel import * does not export add due to __all__ not defined.
fix
Use: from rel import add (or import rel and then rel.add).
gotcha The library is single-threaded by default. Do not assume thread safety; use rel's own async/schedule features for concurrent patterns.
fix Use rel.timeout or rel.schedule for timed callbacks, not threading.Thread.
gotcha EventHandler is deprecated; use the module-level functions (add, fire, remove) instead.
fix Replace EventHandler instances with rel.add() and rel.fire(). Visit documentation for migration.
gotcha When using rel.fire_in() or rel.schedule(), the program will exit immediately unless rel.dispatch() is running. These methods schedule on an internal timer that only fires while dispatch() is active.
fix Call rel.dispatch() (blocking) to start the event loop after scheduling. Use a non-blocking alternative like rel.timeout if you need async in a GUI framework.

Basic usage: add listeners, fire events synchronously or with a delay.

import rel

# Register an event listener
def my_handler(data):
    print(f"Received: {data}")

rel.add('my_event', my_handler)

# Fire an event
rel.fire('my_event', {'key': 'value'})

# Remove listener
rel.remove('my_event', my_handler)

# Fire event after 1 second
rel.fire_in(1.0, 'my_event', 'hello')