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 import Loader
- Load your plugins/modules:
# initialize the loader loader = Loader() # load your plugins plugins = 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.3.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d33b178ff7314046530b230b547af82d903c9bb213e9e89560de52aa7410fd46 |
|
MD5 | b26aca82fe9721b184a369834964de47 |
|
BLAKE2b-256 | 2d8f1898571b242ca3f4a066e02a290676d41563f9a9b24c83c304f3f58f5b2b |
Close
Hashes for simple_plugin_loader-1.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f1440df7dca2ecf11267f0d08595ef4ae341383c11bee749a191d12c945d85d |
|
MD5 | 6374032644cb034c130efaafcd8853ae |
|
BLAKE2b-256 | aaefad56bfab75c097becbb256bd699b072ed8ef1bb981dbe6d5084747cb3499 |