Skip to main content

PyGearBox is a powerful, lightweight, and user-friendly plugin manager designed for Python applications

Project description

pyGearBox

PyGearBox is a powerful, lightweight, and user-friendly plugin manager designed for Python applications. It enables developers to modularize their code by dynamically loading and executing plugins. With PyGearBox, developers can build highly extensible systems that allow easy integration of additional features without modifying the core application logic.

Key Features

  • Dynamic Plugin Loading: Load plugins at runtime, reducing code complexity and improving modularity.
  • Easy-to-Use API: Simple and intuitive methods for loading and executing plugins.
  • Customizable Plugins: Extend your application by creating custom plugins tailored to your needs.
  • Lightweight and Fast: Minimal performance overhead, designed with efficiency in mind.
  • Community-Driven: Fully open source, welcoming contributions and feedback from developers worldwide.
  • Task Executor Ability to scale different types of processing like threaded, parallel, async etc

Example Usage

Below is an example of how to use PyGearBox to manage and execute plugins in your Python application:

from pyGearBox.manager import PyGearBox, PyGearBoxManifest

# Initialize the plugin manager
gearbox = PyGearBox()

# Run the 'simple_hello_world' plugin
simple_plugin = PyGearBoxManifest(name='simple_hello_world')
plugin = gearbox.load_plugin(simple_plugin)
gearbox.run_plugin(plugin)

# Results
>> simple_hello_world loaded
>> Running: Hello, World!

# # Run the 'arg_print' plugin with an argument
arg_plugin = PyGearBoxManifest(name='arg_print', arguments={'custom': 'Hello', 'value': 'World! from arg'})
plugin = gearbox.load_plugin(arg_plugin)
gearbox.run_plugin(plugin)

# Results
>> arg_print loaded
>> Running arg_print plugin
>> Hello World! from arg

gearbox.run_plugins()

for i in gearbox.result:
    print(gearbox.result[i])

>> Status(code=0, message="Successfully ran plugin 'Runnable(instance=<simple_hello_world.PyGearBoxPlugin object at 0x1049c4510>, arguments=None)'")
>> Status(code=0, message="Successfully ran plugin 'Runnable(instance=<arg_print.PyGearBoxPlugin object at 0x104cce210>, arguments={'custom': 'Hello', 'value': 'World! from arg'})'")

Run All Plugins

plugin_list = [
        PyGearBoxManifest(name='simple_hello_world'),
        PyGearBoxManifest(name='arg_print', arguments={'custom': 'Hello', 'value': 'World! from arg'})
    ]

gearbox = PyGearBox(manifests=plugin_list)
gearbox.run_plugins()

Plugin Discovery in PyGearBox

PyGearBox is designed to provide a seamless plugin discovery mechanism, making it easy for developers to load plugins dynamically. Here's how the plugin discovery process works:

Example Scenarios

plugins directory in below examples are available in PYTHONPATH

Direct File Plugins: A plugin named simple_hello_world located as a standalone file in the plugin path:

plugins/
└── simple_hello_world.py

Package and Module Plugins: A plugin named advanced.greetings is part of a package:

plugins/
└── advanced/
    ├── __init__.py
    └── greetings.py

In this case, the plugin is referenced as advanced.greetings during initialization.

Example Plugins

Minimal Plugin

from pyGearBox.plugin import PyGearBoxBasePlugin

class PyGearBoxPlugin(PyGearBoxBasePlugin):
    def __init__(self):
        super().__init__()

    def run(self):
        print("Hello, World!")

    @property
    def name(self):
        return self.__class__.__name__

    @property
    def version(self):
        return '1.0.2'

Task Executor

Linear Executor

  • Simple task / process executor, runs one after the other in a for loop

Plugin Features

You can implement the below methods on the plugin to implement code execution at different stages of plugin management

  • on_load: Executed when the plugin is loaded, used for initialization tasks.
  • on_unload: Executed when the plugin is unloaded, used for cleanup tasks.
  • pre_run: Executed before the main run function, used for setup or pre-processing.
  • post_run: Executed after the main run function, used for teardown or post-processing.
  • run: The main function of the plugin, where its core functionality is implemented.

Upcoming Features

Parallel Executor (WIP / Future)

  • execute task / process executor, in parallel prcosses
  • Use python ProcessPoolExecutor

Async Executor (WIP / Future)

  • execute task / process executor, in asyncronised manner
  • Use python native async

Custom directory plugin discovery

  • Currently plugin discovery is based on PYTHONATH will introduce custom directory based plugin discovery

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

pygearbox-1.1.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

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

pygearbox-1.1.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file pygearbox-1.1.0.tar.gz.

File metadata

  • Download URL: pygearbox-1.1.0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for pygearbox-1.1.0.tar.gz
Algorithm Hash digest
SHA256 811a9e026b5b0a0dad1bdf580fbf2d5d3190a447683c5e38969193a82b624294
MD5 1dda687ba551e2b6b147335dbbe28589
BLAKE2b-256 6cb3c0d40629f72270e36f1a1e4b64054781fe3f5a98175b72613e67adcec453

See more details on using hashes here.

File details

Details for the file pygearbox-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pygearbox-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for pygearbox-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 11c02064ea1c288b83568a3bfecf1fc66c11fc63b4b1ff0f0136ebbd206d031c
MD5 861abc7f5597b585eccd5ee5f14829f7
BLAKE2b-256 b3315c1e6ac72f4d434dd27359e973ae5bb31ba626c702e31c2d235a5e2a6181

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