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-system

Usage

from event_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.1a0.tar.gz (2.5 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.1a0-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file event_plugin_system-0.0.1a0.tar.gz.

File metadata

  • Download URL: event_plugin_system-0.0.1a0.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

Hashes for event_plugin_system-0.0.1a0.tar.gz
Algorithm Hash digest
SHA256 2976ce1a7046be3ad1341a10bee654157c64d92b98a6670811a548b56579cc49
MD5 b41d44adcfcf646d0521bb8ddac16e29
BLAKE2b-256 03ce4ef1b490c090d7736245de4491ae596f12c56b695f5fdf43a483b0c4d09c

See more details on using hashes here.

File details

Details for the file event_plugin_system-0.0.1a0-py3-none-any.whl.

File metadata

File hashes

Hashes for event_plugin_system-0.0.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 13f23533f6a39954dcc988ea6d0387ffccde2f2879a7649cf39e261adfccc16f
MD5 e0da2a26c9fc731665bee059c10c5784
BLAKE2b-256 8c5e36be00a67057951edc80dc53ab3c307787d51d922b4c0f4792a5f1eba20e

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