Overview
Pluginlib makes creating plugins for your project simple.
Features
Plugins are validated when they are imported
Plugins can be loaded through different mechanisms (modules, filesystem paths, entry points)
Multiple versions of the same plugin are supported (The newest one is used by default)
Plugins can be blacklisted by type, name, or version
Multiple plugin groups are supported so one program can use multiple sets of plugins that won’t conflict
Plugins support conditional loading (examples: os, version, installed software, etc)
Once loaded, plugins can be accessed through dictionary or dot notation
Installation
PIP
$ pip install pluginlib
Fedora and EL (RHEL/CentOS/Rocky/Alma)
(EPEL repositories must be configured for EL8)
$ dnf install python3-pluginlib
EL7 (RHEL/CentOS)
(EPEL repositories must be configured)
$ yum install python2-pluginlib
$ yum install python36-pluginlib
Usage
Step 1: Define plugin parent classes
All plugins are subclasses of parent classes. To create a parent class, use the @Parent decorator.
The @Parent decorator can take a plugin type for accessing child plugins of the parent. If a plugin type isn’t given, the class name will be used.
The @Parent decorator can also take a group keyword which restricts plugins to a specific plugin group. group should be specified if plugins for different projects could be accessed in an single program, such as with libraries and frameworks. For more information, see the Plugin Groups section.
Methods required in child plugins should be labeled as abstract methods. Plugins without these methods or with parameters that don’t match, will not be loaded. For more information, see the Abstract Methods section.
"""
sample.py
"""
import pluginlib
@pluginlib.Parent('parser')
class Parser():
@pluginlib.abstractmethod
def parse(self, string):
pass
Step 2: Define plugin classes
To create a plugin, subclass a parent class and include any required methods.
Plugins can be customized through optional class attributes:
- _alias_
Changes the name of the plugin which defaults to the class name.
- _version_
Sets the version of the plugin. Defaults to the module __version__ or None If multiple plugins with the same type and name are loaded, the plugin with the highest version is used. For more information, see the Versions section.
- _skipload_
Specifies the plugin should not be loaded. This is useful when a plugin is a parent class for additional plugins or when a plugin should only be loaded under certain conditions. For more information see the Conditional Loading section.
"""
sample_plugins.py
"""
import json
import sample
class JSON(sample.Parser):
_alias_ = 'json'
def parse(self, string):
return json.loads(string)
Step 3: Load plugins
Plugins are loaded when the module they are in is imported. PluginLoader will load modules from specified locations and provides access to them.
- PluginLoader can load plugins from several locations.
A program’s standard library
A list of modules
A list of filesystem paths
Plugins can also be filtered through blacklists and type filters. See the Blacklists and Type Filters sections for more information.
Plugins are accessible through the PluginLoader.plugins property, a nested dictionary accessible through dot notation. For other ways to access plugins, see the Accessing Plugins section.
import pluginlib
import sample
loader = pluginlib.PluginLoader(modules=['sample_plugins'])
plugins = loader.plugins
parser = plugins.parser.json()
print(parser.parse('{"json": "test"}'))
Metadata
Release files for pluginlib 0.11.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pluginlib-0.11.0.tar.gz | 45.9 kB | Without provenance | Details for pluginlib-0.11.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pluginlib-0.11.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for pluginlib-0.11.0-py2.py3-none-any.whl |
Total release size: 70.5 kB
Release files / pluginlib-0.11.0.tar.gz
| Download URL | pluginlib-0.11.0.tar.gz |
|---|---|
| Size | 45.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
daece55f03d76d0674f481b0c1b73ad877229b721386a14adbe9c9991c9f3025
|
|
BLAKE2b-256 checksum How to use checksums |
edeed768d383cff0128ba30e7088a5d6aa8ed083e2b3ad669be6401c999bf58d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / pluginlib-0.11.0-py2.py3-none-any.whl
| Download URL | pluginlib-0.11.0-py2.py3-none-any.whl |
|---|---|
| Size | 24.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
b75908a832ca053ae3112aba6424e80f406a98ebc0bf6aa3e904b1b2e85a6e01
|
|
BLAKE2b-256 checksum How to use checksums |
05a78d61944116824716072cdf7bc83cf262c2edc7c546cdc4c478ea72ad0dd4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for pluginlib 0.11.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.