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.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20f956bb46096a72069e3893507b25f9559542d6bcd17240d6b048a811fb0c35 |
|
MD5 | 72fa453d3827fa1e340aa7a273f54281 |
|
BLAKE2b-256 | 9bb84c8963b98be9849bf86dedff452f1f849fc552bbcfa740cb0aaa04cee9e0 |
Close
Hashes for simple_plugin_loader-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 714768288160a607a766323e5d2cc9ff707408ad5cd8f1974d6a47d929862b8e |
|
MD5 | f4b86bbc98503ef3e3fb985df6ad2d95 |
|
BLAKE2b-256 | 0b5f71662079a331caafbacb202656bc1dd9d4dde5a1a128f8a9663516eb7556 |