Simple Python Plugin Loader
This module provides a simple way to dynamically load other Python modules as Plugins to your current project.
Install
You can install this python module via pip:
pip install simple-plugin-loader
Otherwise the module can be downloaded from PyPI: https://pypi.org/project/simple-plugin-loader/
Usage
- Import the module:
from simple_plugin_loader import Loader
- Load your plugins/modules:
loader = Loader()
plugins = loader.load_plugins(<plugin_path>, <plugin_base_class>, <specific_plugins>, <recursive>)
- (Optional) The already loaded plugins/modules can be accessed via the
plugins
property of the loader instance:
plugins = loader.plugins
load_plugins(...)
Method
This method does the actual plugin loading.
It loads only Python modules that can be executed in the current environment. For every successfully loaded module a message is populated through the Python logging
library (log level: INFO
).
If a module e.g. contains syntax errors or depends on other not installed Python modules, it will be skipped. So the main program does not fail completely. An error message is populated through the Python logging
library (log level: ERROR
).
Arguments
Return value
The method returns a dictionary that has the following structure:
- Key: The name of the plugin/module. This name is the module name of the module that contains the plugin class.
- Value: The plugin class. Not an instance!