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 plugin_loader.loader import Loader
- Load your plugins/modules:
# initialize the loader loader = Loader() # load your plugins plugins = self.loader.load_plugins(<plugin_path>, <plugin_base_class, <recursive>)
- (Optional) The already loaded plugins/modules can be accessed via the
plugins
property of the loader instance:plugins = loader.plugins
load_plugins(...)
Method
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 plugin_loader.sample_plugin import SamplePlugin class YourPlugin(SamplePlugin): pass
<recursive>
: bool (Default:False
)
Set this flag toTrue
if you wish to load plugins/modules recursively to the above directory.
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
Close
Hashes for simple-plugin-loader-1.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b8377df6a59a321503e287ef4443455c1d0e45948c53ca421d7ba60ef4aec49 |
|
MD5 | 3d2feed02771e5249fb054ef311e0801 |
|
BLAKE2b-256 | 96a10f5d545f2d33c27415ef9ed570ccb8959438287976408b766f84bff4b417 |
Close
Hashes for simple_plugin_loader-1.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 426097de83471664ea3af44d916b414a88bc9ca5d8d7f3bbca454878cd677c67 |
|
MD5 | f11118da30c9f883e867bea9230bd000 |
|
BLAKE2b-256 | 11ffef2b6b1d872cb85a4f28420fbcc22322e58f3429d19919abd0f7bb7b482f |