Dynamically load other python modules to your project
Project description
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:
# initialize the loader loader = Loader() # load your plugins plugins = loader.load_plugins(<plugin_path>, <plugin_base_class>, <specific_plugins>, <recursive>, <verbose>)
- (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. 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.
Arguments
<plugin_path>
: str
This string represents the path (relative or absolute) to the directory from where the plugins/modules should be loaded.<plugin_base_class>
: class (Default:SamplePlugin
)
The Loader does not load all found modules that are in the above directory. It only loads classes that are sub-classes of the here specified class.
The default value of this argument is theSamplePlugin
class. You can use this class as the base class for your plugins:from simple_plugin_loader.sample_plugin import SamplePlugin class YourPlugin(SamplePlugin): pass
<specific_plugins>
: List[str] (Default:[]
)
This list can contain case sensitive class names, that should be loaded. Then no other plugins will be loaded. The argument<plugin_base_class>
will also be ignored, so any class can be loaded.<recursive>
: bool (Default:False
)
Set this flag toTrue
if you wish to load plugins/modules recursively to the above directory.<verbose>
: bool (Default:False
)
This flag controls the debug output of this method. If enabled, information about (not) loaded plugins/modules are printed.
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!
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
Hashes for simple-plugin-loader-1.6.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea69b6564a909b8b8c83028b0c17237f2bac282f1be2a57763e13909836d048d |
|
MD5 | 98d68b7302403c047e50578f29b3f236 |
|
BLAKE2b-256 | 0e19649453f9b4338e7d6fefe46d9424766e9c6dc4d3a1acc9215cb8368da9c8 |
Hashes for simple_plugin_loader-1.6.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9063a0ef3865e069a87cf30018c4426b422bba976779f695bffb15b36d5ae667 |
|
MD5 | 038c13faf73c6fa0a4425242aa22a72a |
|
BLAKE2b-256 | dceb3519eeb87d3bc94df247885dd615d27c84a484485c137d9ca2a4494159ef |