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.
Installation
pip install event_emitter_asyncio
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
rm -rf dist && python3 -m build
twine upload dist/*
Metadata
Release files for event-emitter-asyncio 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| event_emitter_asyncio-1.0.4.tar.gz | 3.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| event_emitter_asyncio-1.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.4 kB
Release files / event_emitter_asyncio-1.0.4.tar.gz
| Download URL | event_emitter_asyncio-1.0.4.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e3a36633d0f27991d415b61ce79cdcd727a23d4f62b941974500310084fcb8a1
|
|
BLAKE2b-256 checksum How to use checksums |
dcd23cf9d346ac0ac0f7137859ea6069a8ea65ece07c6b9be92c52f028a7ecc3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.6
|
Release files / event_emitter_asyncio-1.0.4-py3-none-any.whl
| Download URL | event_emitter_asyncio-1.0.4-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
92eeaf634f04490a1624cd09fea643a4212f3aa584360f3634e17716f47f777f
|
|
BLAKE2b-256 checksum How to use checksums |
662db27a2425d68c4cfd11c21443aa0da3cdd2b1ce82ca23334ec52c1d9705dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.6
|