Skip to main content

PlugyPy

plugypy

Installation

You can install the plugin system from PyPi with:

pip install PlugyPy

Or locally by cloning the repository:

git clone https://github.com/not-so-cool-anymore/plugypy.git

and then running the setup file in the main directory with:

pip install .

Writing a configuration file

A PlugyPy configuration (or config) file is a JSON file that contains a deserialized representation of a PlugyPy Configuration object. The Configuration object consists of a boolean named will_load_all and a list named plugins. plugins is a list of PlugyPy Plugin objects will_load_all determines whether all of the plugins in the plugins directory will be loaded or only the enabled ones.

An example of a config file is:

{
    "will_load_all": true,
    "plugins": [
        {
            "name": "example_plugin_name_0",
            "is_enabled": true
        },
        {
            "name": "example_plugin_name_1",
            "is_enabled": false
        },
        {
            "name": "example_plugin_name_2",
            "is_enabled": true
        }
    ] 
}

Where name is the name of the plugin file without the .py file extension, and enabled is the boolean variable that indicates whether a plugin will be loaded (when true) or not (when false).

Usage

Importing the plugin system:

import plugypy

Deserializing JSON configuration file into a Configuration object.

configuration_deserializer = ConfigurationDeserializer('/path/to/configuration/file')
configuration = configuration_deserializer.deserialize_config()

Creating a plugin manager object:

plugin_manager = plugypy.PluginManager('/path/to/plugins/directory', configuration)

The plugin manager object has one extra feature - plugin ownership verification. This feature ensures that the plugin that is being executed belongs to the current user (or if sudo is used to run the program - the sudo caller). This feature can be activated via parsing one extra argument - will_verify_ownership=True, which is set to False by default when not passed.

Discovering plugins:

discovered_plugins = plugin_manager.discover_plugins()

discover_plugins is a list of all the plugins in a given plugins directory.

Importing plugins:

plugins_list = plugin_manager.import_plugins(discovered_plugins)

plugins_list is a list of map objects that has a name key and an object value of the imported executable Python module (plugin executable).

Importing a singe plugin by file name:

single_plugin = plugin_manager.import_plugin('PLUGIN_FILENAME_WITHOUT_PY_EXTENSION')

In this case, the plugin will be imported no matter if a configuration for it exists. This importing method is developed for edge cases in which the imported plugin will be executed only once.

Getting a plugin's information:

plugin_name = plugins_list[n]['name']
plugin_executable_object = plugins_list[n]['object']

n is an index of a plugin.

Executing a plugin's function with no parameters:

plugin = plugins_list[n]
plugin_result = plugin_manager.execute_plugin_function(plugin, 'function_name')

if plugin_result == None:
    print('The plugin returned no result')
else:
    print('The plugin returned: {}'.format(result))

n is an index of a plugin.

Executing a plugin's function with parameters:

plugin = plugins_list[n]

arguments_tuple = ('arg1', 'arg2', 'arg3')
plugin_result = plugin_manager.execute_plugin_function(plugin, 'function_name', args=arguments_tuple)

if plugin_result == None:
    print('The plugin returned no result')
else:
    print('The plugin returned: {}'.format(result))

n is an index of a plugin.

args must be a tuple of argument/s.

Metadata

Release files for PlugyPy 1.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PlugyPy 1.2.2
File Size Uploaded
PlugyPy-1.2.2.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for PlugyPy 1.2.2
File Interpreter ABI Platform
PlugyPy-1.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 22.2 kB

Release files / PlugyPy-1.2.2.tar.gz

Download URL PlugyPy-1.2.2.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
dc17c8f6cf2e2eee3b32cd607430957440649caf243e2c99daf3fe00c651ac2a
BLAKE2b-256 checksum
How to use checksums
147c3bd286d7ae392f0df84dfda987252b103a392cbbd1412317318f0722954a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.25.1 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.9

Release files / PlugyPy-1.2.2-py3-none-any.whl

Download URL PlugyPy-1.2.2-py3-none-any.whl
Size 18.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a89b6d25097f89218a6db24506137571e2ab62499247f4e64d279ceda75cc791
BLAKE2b-256 checksum
How to use checksums
d037a2c6e12603de0ed88862cf3ec060b5a19f329ce68a54c85f94a8fe64c7af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.25.1 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.9

Release history Release notifications | RSS feed

This release

1.2.2 This release

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page