Skip to main content

eventpy is a Python event library that provides tools that enable your application components to communicate with each other by dispatching events and listening for them. With eventpy you can easily implement signal/slot mechanism, or observer pattern.

Project description

eventpy -- Python library for event dispatcher and callback list

eventpy is a Python event library that provides tools that enable your application components to communicate with each other by dispatching events and listening for them. With eventpy you can easily implement signal/slot mechanism, or observer pattern.
This library is the Python version rewritten from the C++ library eventpp, both are developed by the same developer.

Facts and features

  • Powerful
    • Supports synchronous event dispatching and asynchronous event queue.
    • Configurable and extensible with policies.
  • Robust
    • Supports nested event. During the process of handling an event, a listener can safely dispatch event and append/prepend/insert/remove other listeners.
    • Thread safety. Supports multi-threading.
    • Well tested. Backed by unit tests.
  • Flexible and easy to use
    • Listeners and events can be of any type and do not need to be inherited from any base class.
    • Requires Python 3. Tested with Python 3.7 and Cython.

License

Apache License, Version 2.0

Version 0.0.1

eventpy is currently usable and stable.

Source code

https://github.com/wqking/eventpy

Quick start

Install

pip install eventpy

Package

eventpy

Using CallbackList

# create a CallbackList
callbackList = CallbackList()
callbackList.append(lambda s, b : print("Got callback 1, s is %s b is %d" % (s, b)))
def anotherCallback(s, b) :
	print("Got callback 2, s is %s b is %d" % (s, b))
callbackList.append(anotherCallback)
# Invoke the callback list
callbackList("Hello world", True)

Using EventDispatcher

# create an EventDispatcher
dispatcher = EventDispatcher()

dispatcher.appendListener(3, lambda s, b : print("Got event 3, s is %s b is %d" % (s, b)))
dispatcher.appendListener(5, lambda s, b : print("Got event 5, s is %s b is %d" % (s, b)))
dispatcher.appendListener(5, lambda s, b : print("Got another event 5, s is %s b is %d" % (s, b)))

# Dispatch the events, the first argument is always the event type.
dispatcher.dispatch(3, "Hello", True)
dispatcher.dispatch(5, "World", False)

Using EventQueue

# create an EventQueue
queue = eventqueue.EventQueue()
queue.appendListener(3, lambda s, n : print("Got event 3, s is %s n is %d" % (s, n)))
queue.appendListener(5, lambda s, n : print("Got event 5, s is %s n is %d" % (s, n)))
queue.appendListener(5, lambda s, n : print("Got another event 5, s is %s n is %d" % (s, n)))

# Enqueue the events, the first argument is always the event type.
# The listeners are not triggered during enqueue.
queue.enqueue(3, "Hello", 38)
queue.enqueue(5, "World", 58)

# Process the event queue, dispatch all queued events.
queue.process();

Documentations

Run the unit tests

Go to the root folder of eventpy, run python -m pytest

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

eventpy-0.0.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

eventpy-0.0.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file eventpy-0.0.1.tar.gz.

File metadata

  • Download URL: eventpy-0.0.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.4

File hashes

Hashes for eventpy-0.0.1.tar.gz
Algorithm Hash digest
SHA256 40ecdc2db438fc7504820197d49748c17ab8e24bbd9f03db71b2dda596364f50
MD5 30a1f5bfeae0a5a93ce32f01616cb919
BLAKE2b-256 92379b2ab8cb9a5e5c92502053966631f854108f3dd72e431a5c8a22cf1a18a4

See more details on using hashes here.

File details

Details for the file eventpy-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: eventpy-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.4

File hashes

Hashes for eventpy-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0ae66551adadd2dbae96445a864bbc6fec8df599a04b3807b243f27401dd910d
MD5 0558afcfd72f867f6b6bebe41fd0c33d
BLAKE2b-256 ef63b0e681046fa0c7f2b1bdc0a853695aaf3464b8b772ba32b15953b4ff34c4

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