UNKNOWN
Project description
Eventlite
Light “events” for Python functions.
Abstract
The purpose of this library is to provide an “abstract” way for functions to “report” events, in a way similar to how a logging system operates.
Some example applications:
A logging system: emit('log', 'My message', level='info')
Reporting progress on some running operation emit('progress', current=20, total=100)
Note that the event structure is not imposed in any way; in fact, any combination of arguments/keywords can be used, proven that the handler function is able to handle it.
Example usage
import eventlite
def myfunction(foo):
eventlite.emit(foo)
def handler(foo):
print('You said: {0}'.format('Hello'))
with eventlite.handler(handler):
myfunction('Hello')
API Documentation
The library provides two functions:
eventlite.emit(*a, **kw) “emits” an “event” (represented by a variable number of arguments / keywords).
eventlite.handler(function) returns a context manager that makes events to be dispatched to a certain function, while the context is active.
So, in the example above, when eventlite.emit() is called with one argument, handler() will be called passing the single argument to it.
Internals
All the magic is implemented using a LocalStack (borrowed from werkzeug) which keeps a stack of handlers to be called, for the local proxy. The emit() functon simply looks for an handler in the stack to which to dispatch the event.
Note: by default only the handler for the innermost context manager is called; this might or might not be the desired behavior; some way to change this will be added in the future.
Links
PyPI page: https://pypi-hypernode.com/pypi/eventlite
Source code: https://github.com/rshk/eventlite
History
v0.1a
Initial version, with handling of simple events through a context-manager dispatching to “contexts” in a thread-local stack.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file eventlite-0.1.1.tar.gz
.
File metadata
- Download URL: eventlite-0.1.1.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 438aebdc5833a8e90c69f95f346b46ee700d847a2e69d28f00f7f2825b08e417 |
|
MD5 | 3507a21dba8c601cc083699410fc71b3 |
|
BLAKE2b-256 | 96c89ffe696b11a07cbc6b466499dabd19b36d90813ef250fe56c6055eae157e |