PyEventEmitter
Python events library, heavily inspired by Node.js’ EventEmitter.
Installation
$ pip install PyEventEmitter
How to use
The library provides an EventEmitter class. This class let you bind listeners to events and trigger events.
import event_emitter as events
em = events.EventEmitter()
def hello(who):
print('Hello {}'.format(who))
em.on('hello', hello)
em.emit('hello', who='World') # prints Hello World
You can also use on decorator :
import event_emitter as events
em = events.EventEmitter()
@events.on(emitter=em, event='hello')
def hello(who):
print('Hello {}'.format(who))
em.emit('hello', who='World') # prints Hello World
Using once instead of on may be usefull if you want your listener to be called once :
import event_emitter as events
em = events.EventEmitter()
def hello(who):
print('Hello {}'.format(who))
em.once('hello', hello)
em.emit('hello', who='World') # prints Hello World
em.emit('hello', who='World') # nothing happens
Of course, there is also a decorator for this :
import event_emitter as events
em = events.EventEmitter()
@events.once(emitter=em, event='hello')
def hello(who):
print('Hello {}'.format(who))
em.emit('hello', who='World') # prints Hello World
You can remove a listener bound to an event :
import event_emitter as events
em = events.EventEmitter()
def hello(who):
print('Hello {}'.format(who))
em.on('hello', hello)
em.remove('hello', hello)
em.emit('hello', who='World') # nothing happens
Please note that this method will remove at moste one listener from the list. If the same listener was bound multiple times to the event, this method has to be invoked multiple times to remove all the occurences.
You can also remove all listeners bound to an event thanks to remove_all.
The count method returns the number of listeners bound to an event :
import event_emitter as events
em = events.EventEmitter()
def hello(who):
print('Hello {}'.format(who))
em.on('hello', hello)
print(em.count('hello')) # prints 1
Metadata
Release files for PyEventEmitter 1.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| PyEventEmitter-1.0.5.tar.gz | 2.2 kB | Without provenance | Details for PyEventEmitter-1.0.5.tar.gz |
Release files / PyEventEmitter-1.0.5.tar.gz
| Download URL | PyEventEmitter-1.0.5.tar.gz |
|---|---|
| Size | 2.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a7639ab46d0c14c3f35e020bcbd55a71faeee32295a9fb4e06865e904695d2d
|
|
BLAKE2b-256 checksum How to use checksums |
71c4c9cc29d18de18d97269ee5794e0d212d1f981e4a95e06df93d7c2bab102e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
|
Security for PyEventEmitter 1.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.