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 pluginbaseVerified import paths — ran on the pinned version, not inferred.
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.
Always wrap your plugin imports in a `with plugin_source:` block or use `plugin_source.load_plugin()` for programmatic loading.
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.
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`.
Install the library using pip: `pip install pluginbase`
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()
```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
```No dependency data recorded yet.