Classy Events
Pythonic event-driven programming.
Dependencies
Python 3.8, 3.9
Install
pip install classy-events
Usage
The main ingredient is an event handler instance:
from classy_events import EventHandler
event_handler = EventHandler()
You can register event listeners for events of any type. In this example we use string events. An event listener is a callable, like a function or a method. The registered event handlers for a specific event are called if that event is dispatched by the event handler. Any keyword arguments that accompany the event are passed to the event listeners.
Function listeners
The listener for the event "spam", no callbacks needed!
@event_handler.on("spam")
def spam(value):
print(f"on 'spam': '{value}'")
When the "spam" event is dispatched from anywhere in the code, def spam will be called:
event_handler.dispatch("spam", value="ham and eggs")
Now on 'spam': 'ham and eggs' is printed.
Classy listeners
To use instance methods as listeners, only one extra step is needed:
class Spam:
def __init__(self):
event_handler.bind(self)
@event_handler.on("classy_spam")
def spam(self, value):
print(f"on '{type(self).__name__}.spam': '{value}'")
spam_instance = Spam()
In __init__, the instance is bound to the handler. Note that this
event_handler.bind call is not required to be within the __init__.
To see this in action, we dispatch the "classy_spam" event:
event_handler.dispatch("classy_spam", value="the classiest")
And we see the output on 'Spam.spam': 'the classiest'.
Metadata
Release files for classy-events 0.3.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 | Provenance | Actions |
|---|---|---|---|---|
| classy-events-0.3.4.tar.gz | 21.6 kB | Without provenance | Details for classy-events-0.3.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| classy_events-0.3.4-py3-none-any.whl | Python 3 | none | any | Details for classy_events-0.3.4-py3-none-any.whl |
Total release size: 43.1 kB
Release files / classy-events-0.3.4.tar.gz
| Download URL | classy-events-0.3.4.tar.gz |
|---|---|
| Size | 21.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3160f5b4e8acaee3b1d1c86843096fbba83b1401e5be5bf4a8e13cdb1530abd4
|
|
BLAKE2b-256 checksum How to use checksums |
4fec6195500a1b470ef2bfa0ae0899b19afaac9fe429d1142ea56cd13cca4ba2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
|
Release files / classy_events-0.3.4-py3-none-any.whl
| Download URL | classy_events-0.3.4-py3-none-any.whl |
|---|---|
| Size | 21.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f87aa6bbe553530bc97aa300d3f8456cfe5cac10bf889cfbfdf47f6bd7357a60
|
|
BLAKE2b-256 checksum How to use checksums |
a0dfc9ed838fe45ff3485ff9a993b0d043eca7e83ba73ef1f7f021a562d50810
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
|
Security for classy-events 0.3.4
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.