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.1.1.tar.gz (7.2 kB view details)

Uploaded Source

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

Hashes for eventlite-0.1.1.tar.gz
Algorithm Hash digest
SHA256 438aebdc5833a8e90c69f95f346b46ee700d847a2e69d28f00f7f2825b08e417
MD5 3507a21dba8c601cc083699410fc71b3
BLAKE2b-256 96c89ffe696b11a07cbc6b466499dabd19b36d90813ef250fe56c6055eae157e

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