Skip to main content

Dynamically load other python modules to your project

Project description

Simple Python Plugin Loader

PyPI package PyPI version

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

  1. Import the module:
    from simple_plugin_loader import Loader
    
  2. Load your plugins/modules:
    # initialize the loader
    loader = Loader()
    
    # load your plugins
    plugins = loader.load_plugins(<plugin_path>, <plugin_base_class>, <specific_plugins>, <recursive>)
    
  3. (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
  • <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 the SamplePlugin 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 to True 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple-plugin-loader-2.2.2.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_plugin_loader-2.2.2-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file simple-plugin-loader-2.2.2.tar.gz.

File metadata

  • Download URL: simple-plugin-loader-2.2.2.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12

File hashes

Hashes for simple-plugin-loader-2.2.2.tar.gz
Algorithm Hash digest
SHA256 37a7cd1dcbde532ce559728ffb00ef3f3e202496a3677e3f82aa1a34507d484d
MD5 d483a49da222ce126229dc1ec41e2acc
BLAKE2b-256 883681cc4f6d18d556aa95cddd7dcc0758efc5c37709dc826b1a10659a9a002d

See more details on using hashes here.

File details

Details for the file simple_plugin_loader-2.2.2-py3-none-any.whl.

File metadata

  • Download URL: simple_plugin_loader-2.2.2-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12

File hashes

Hashes for simple_plugin_loader-2.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0b5f470fad20a658b8af65752ce27738e1304d364adb1c4dea29f2f5d8df126a
MD5 8080b3bcb8220a9cf6ad50b1d15b7317
BLAKE2b-256 a28c72e9f6e65f205276cc46f3a397d347e36972ff8cca3dafc806afa47f3350

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page