Skip to main content

UNKNOWN

Project description

Eventlite

Light “events” for Python functions.

Latest PyPI version Number of PyPI downloads Supported Python versions Development Status License

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.

History

v0.1a

  • Initial version, with handling of simple events through a context-manager dispatching to “contexts” in a thread-local stack.

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

eventlite-0.1a.tar.gz (6.0 kB view details)

Uploaded Source

File details

Details for the file eventlite-0.1a.tar.gz.

File metadata

  • Download URL: eventlite-0.1a.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for eventlite-0.1a.tar.gz
Algorithm Hash digest
SHA256 ce818cbffca6c9f36c10303dee2f13bf6947cb77f477ffce0fd7278978b4daf8
MD5 a46aebe9b7bef2d42f042170796a268f
BLAKE2b-256 8ad5251435bdc92c876196b25beafa488a5e52b3e58b1ae8bdf0a43e85f422c7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page