Bringing the elegance of C# EventHanlder to Python
The C# language provides a handy way to declare, subscribe to and fire events. Technically, an event is a “slot” where callback functions (event handlers) can be attached to - a process referred to as subscribing to an event. Here is a handy package that encapsulates the core to event subscription and event firing and feels like a “natural” part of the language.
>>> def something_changed(reason): ... print "something changed because %s" % reason ... >>> from events import Events >>> events = Events() >>> events.on_change += something_changed
Multiple callback functions can subscribe to the same event. When the event is fired, all attached event handlers are invoked in sequence. To fire the event, perform a call on the slot:
>>> events.on_change('it had to happen') 'something changed because it had to happen'
Complete documentation is available at http://events.readthedocs.org
Events is on PyPI so all you need to do is:
pip install events
python setup.py test
Or use tox to test the package under all supported Pythons: 2.6, 2.7, 3.3, 3.4.
Events is BSD licensed. See the LICENSE for details.
Please see the Contribution Guidelines.
Based on the excellent recipe by Zoran Isailovski, Copyright (c) 2005.