Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

event_plugin_system-0.0.3.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

event_plugin_system-0.0.3-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file event_plugin_system-0.0.3.tar.gz.

File metadata

  • Download URL: event_plugin_system-0.0.3.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for event_plugin_system-0.0.3.tar.gz
Algorithm Hash digest
SHA256 887c536be6146bf38ba95751c12b0ddf6deff0a4065eaf70012a417941644412
MD5 bcc57f9e9c9ea9f97012bb28f50a4c0c
BLAKE2b-256 4c71aa79d9b27483f2980a23bdfcb7786a2971659d083b5bae3a9a4b04fefaf8

See more details on using hashes here.

File details

Details for the file event_plugin_system-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for event_plugin_system-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 358ebbdb10865e521b5d82fa38447c4aa69453c1e0fe8f6f7c294fff9ab912f3
MD5 6f6e97412c193e10398fa66e6ad6afba
BLAKE2b-256 888991346b2d7cf51fa55c7d0c25879a5b1732325bcb33ac7a2edf597916b84a

See more details on using hashes here.

Supported by

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