Graph-IT

Event Module

This is a small Python module that provides classes with the possibility to register and emit events.

Installation

The event module can be installed with pip directly from our git repository:

$ pip install git+git://git.graph-it.com/graphit/event-py.git

Usage

The module provides an abstract EventEmitterInterface and a class EventEmitterMixin implementing it.

Classes that want to emit events should extend the EventEmitterMixin and call self._emit(event, *args, **kwargs) at appropriate locations in their code. The designations of the events can be any kind of hashables.

Listener callbacks can then be registered with the on(event, callback) method. The callbacks should receive exactly the arguments provided in the self._emit calls. A handle to the registration is returned by the call to on, which can be used to unregister the callback again by the off(handle) method.

A simple example can be found in the example.py script in the git repositiory.