Super simple event emitter in Python 3, built with asyncio. No decorators required.
Project description
event-emitter-asyncio
Super simple event emitter in Python 3, built with asyncio. No decorators required. Built around a subset of the NodeJS EventEmitter API.
A full write up and explanation for how this module works can be found here.
Usage (Working example)
import asyncio
from event_emitter_asyncio.EventEmitter import EventEmitter
event_emitter = EventEmitter()
async def run():
# add a listener
async def func(event):
for pet in event['pets']:
print(pet)
event_emitter.add_listener('some-event', func)
# emit an event every second for 3 seconds
n = 0
while n < 3:
event_data = { 'pets': ['cats', 'dogs'] }
event_emitter.emit('some-event', event_data)
await asyncio.sleep(1)
n += 1
# remove the listener
event_emitter.remove_listener('some-event', func)
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
This will give:
> cats
> dogs
> cats
> dogs
> cats
> dogs
Developing on this repo
Development
git clone git@github.com:joeltok/event-emitter-asyncio.git
cd ./event-emitter-asyncio
python3 -m venv ./venv
source venv/bin/activate
pip3 install pytest
pip3 install pytest-asyncio
Testing
python3 -m pytest src/event_emitter_asyncio/
Packaging
source venv/bin/activate
python3 -m pip install --upgrade build
python3 -m pip install --upgrade twine
python3 -m build
twine upload dist/*
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for event_emitter_asyncio-1.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7139a162dc70ad6ec9b325c4cfa2f7f5118a00eafc061d8fd46d023c7b74ae71 |
|
MD5 | e574e600e65ac581c4e34e95188f12fc |
|
BLAKE2b-256 | 1bd07230ce40920e514aeb1ee62e901de121023e41357778568684a68b0e0af5 |
Close
Hashes for event_emitter_asyncio-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64ff7e83d7fb7fa12546b93c0bef10d98cd9cb212f100eeecd61d11999f0aff7 |
|
MD5 | 9537d0614042209de2cfd69719caf0d5 |
|
BLAKE2b-256 | e39f89d31dd8c43e512f85020bbd90a4f5585a81e0c9a7b85a9cf09c00e0e6ad |