Registry / devops / pluginbase

pluginbase

JSON →
library1.0.1pypypi✓ verified 21d ago

PluginBase is a module for Python that enables the development of flexible plugin systems. It extends the import system to provide a consistent experience for plugins loaded from various sources, allowing applications to incorporate plugins from bundled or custom directories without bypassing the standard Python import mechanism. It offers a distinct approach compared to setuptools-based plugins, focusing on the virtualization and isolation of plugins rather than their distribution via PyPI. The library currently stands at version 1.0.1 and has a stable, albeit infrequent, release cadence, with the latest update in May 2021.

pip install pluginbase
INSTALL
IMPORT
SIG · PLUGINBASE
P
pluginbase
devopspythonv1.0.1
Install
2.4s avg
Import
31ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.034s · 19.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.4s · import 0.028s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PluginBase
from pluginbase import PluginBase
The primary class for setting up a plugin system.

This quickstart demonstrates how to initialize PluginBase, define a plugin source, and then import or load a plugin. Plugins must be imported within the context of an active plugin source. The example creates a temporary plugin file for demonstration.

from pluginbase import PluginBase import os # Define a pseudo-package for your plugins plugin_base = PluginBase(package='my_app.plugins') # Define a source for your plugins, specifying search paths # In a real app, this might be a configurable path or a directory next to your main script. plugin_dir = os.path.join(os.path.dirname(__file__), 'plugins') os.makedirs(plugin_dir, exist_ok=True) # Create a dummy plugin file for demonstration with open(os.path.join(plugin_dir, 'my_plugin.py'), 'w') as f: f.write('def greet():\n return "Hello from my_plugin!"') plugin_source = plugin_base.make_plugin_source( searchpath=[plugin_dir] ) # To import a plugin, activate the plugin source using a 'with' statement with plugin_source: from my_app.plugins import my_plugin print(my_plugin.greet()) # Alternatively, load a plugin programmatically my_other_plugin = plugin_source.load_plugin('my_plugin') print(my_other_plugin.greet())
Debug
Known issues
gotchaPlugins loaded via PluginBase must be imported within the context of an active `plugin_source` using a `with` statement. Attempting to import a plugin outside this context will result in an `ImportError` with a descriptive message.
fix
Always wrap your plugin imports in a `with plugin_source:` block or use `plugin_source.load_plugin()` for programmatic loading.
affects: All versions
gotchaPluginBase provides a system for virtualizing and loading plugins from arbitrary paths, but it is not designed for distributing plugins via PyPI like setuptools entry points. These two approaches solve different problems and are architecturally incompatible.
fix
Understand the core purpose: PluginBase is for in-application, flexible plugin loading from specified directories, not for package distribution. If you need PyPI-based plugin distribution, consider setuptools entry points instead.
affects: All versions
gotchaBe aware that the name 'PluginBase' is common across various ecosystems (e.g., Microsoft Dataverse, Tekla, Shopware, and other Python projects). Ensure you are importing and using the `pluginbase` library by Armin Ronacher (mitsuhiko/pluginbase on GitHub) when targeting this specific Python library, as other 'PluginBase' classes will have different APIs and functionalities.
fix
Always verify your imports and documentation against the official `mitsuhiko/pluginbase` source to avoid confusion with unrelated `PluginBase` implementations. Check the `import` statement `from pluginbase import PluginBase`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pluginbase'
The 'pluginbase' library is not installed in your Python environment or is not accessible within the current Python path.
fix
Install the library using pip: `pip install pluginbase`
The import will fail with a descriptive error message explaining that a plugin source needs to be activated.
You are attempting to import a plugin module using the virtual package defined by `pluginbase` without first activating the `PluginSource` object via a `with` statement or using `plugin_source.load_plugin()`.
fix
Ensure you wrap your plugin imports within a `with plugin_source:` block or use `plugin_source.load_plugin('plugin_name')`.

Example:
```python
from pluginbase import PluginBase

plugin_base = PluginBase(package='my_app.plugins')
plugin_source = plugin_base.make_plugin_source(searchpath=['./plugins'])

# Correct way to import:
with plugin_source:
    from my_app.plugins import my_plugin
    my_plugin.run()

# Alternative correct way:
my_plugin_alt = plugin_source.load_plugin('my_plugin')
my_plugin_alt.run()
```
ModuleNotFoundError: No module named 'yourapplication.plugins.my_plugin'
When using `pluginbase`, this error indicates that the specified plugin module ('my_plugin' in this example) could not be found within the `searchpath` configured for the `plugin_source`, or the module name is incorrect, or the plugin file is missing.
fix
Verify that the plugin file (e.g., `my_plugin.py`) exists in one of the directories specified in the `searchpath` when creating `plugin_source` and that the import name matches the file name (without the .py extension). Also, ensure the `package` argument in `PluginBase` correctly reflects the desired import hierarchy.

Example:
Assuming `your_app/plugins/my_plugin.py` exists:
```python
from pluginbase import PluginBase

plugin_base = PluginBase(package='yourapplication.plugins')
plugin_source = plugin_base.make_plugin_source(searchpath=['./your_app/plugins'])

with plugin_source:
    from yourapplication.plugins import my_plugin # This will now find your_app/plugins/my_plugin.py
```
Upgrade
Version history
1.0.1latest on PyPI · released May 16, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
pluginbase — pip install pluginbase · libregistry