A simple plugin event system
Project description
Event System
A simple plugin event system designed to handle events with plugins dynamically loaded from a specified directory.
Features
- Load plugins from a directory.
- Emit events that plugins can handle.
- Support for both synchronous and asynchronous event handling.
Installation
To install the package, use:
pip install event-plugin-system
Usage
from event_plugin_system import EventPluginSystem
# Specify the directory containing your plugins
plugin_dir = "path/to/your/plugins"
# Initialize the event system
event_system = EventPluginSystem(plugin_dir=plugin_dir)
# Emit an event
event_system.emit("start")
# Emit an event with arguments
results = {}
event_system.emit("arg_pass2", arg="test", results=results)
# Check results
print(results)
Plugin Structure
Each plugin should be a Python file in the specified plugin directory and contain a class named Plugin. The class should define methods with names following the pattern handle_<event_name>.
Example Plugin (simple_echo.py):
class Plugin:
def handle_start(self, **kwargs):
print("Start event received.")
def handle_arg(self, arg, **kwargs):
print(f"Arg received: {arg}")
Asynchronous Support
For asynchronous event handling, use EventPluginSystemAsync:
from event_system import EventPluginSystemAsync
async_event_system = EventPluginSystemAsync(plugin_dir=plugin_dir)
await async_event_system.emit("start")
Testing
pytest tests/
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file event_plugin_system-0.0.2.tar.gz.
File metadata
- Download URL: event_plugin_system-0.0.2.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16679c971f51e2fbed214f88fca99e959a2081dc070fc578a73bb96221e71d8c
|
|
| MD5 |
8e21344f7e159545e91a3840b64da39a
|
|
| BLAKE2b-256 |
5c42cbb910416169be2d74a16dfa46811c3925cccc55021217a42e2615957bfc
|
File details
Details for the file event_plugin_system-0.0.2-py3-none-any.whl.
File metadata
- Download URL: event_plugin_system-0.0.2-py3-none-any.whl
- Upload date:
- Size: 2.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
609a93f490e6c4a3c161fa5c88ddcbc11c2ebe9a5cef6f21a3587929272282fd
|
|
| MD5 |
325de4d3bc440c1025130eba1aeb987a
|
|
| BLAKE2b-256 |
2b680e0e3b63c533e2f7596c32f4e3950d1f1f426ae824772cb5e1033c8f5f81
|