Super simple event bus in Python 3, built with asyncio. No decorators required. Built around a subset of the NodeJS EventEmitter API.
A PyPI package implementing this as a module can be found here.
A full write up and explanation can be found here.
from py_event_bus.EventBus import EventBus
event_bus = EventBus()
async def func(event):
for pet in event['pets']:
print(pet)
event_data = {
'pets': ['cats', 'dogs']
}
event_bus.add_listener('some-event', func)
event_bus.emit('some-event', event_data)
event_bus.remove_listener('some-event', func)
This will give:
> cats
> dogs
git clone [email protected]:joeltok/py-event-bus.git
cd ./py-event-bus
python3 -m venv ./venv
source venv/bin/activate
pip3 install pytest
pip3 install pytest-asyncio
python3 -m pytest event_bus/ event_bus_advanced_examples/