{"id":5007,"library":"pluginbase","title":"PluginBase","description":"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.","status":"active","version":"1.0.1","language":"en","source_language":"en","source_url":"http://github.com/mitsuhiko/pluginbase","tags":["plugins","extension","framework","dynamic-loading","import-system"],"install":[{"cmd":"pip install pluginbase","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The primary class for setting up a plugin system.","symbol":"PluginBase","correct":"from pluginbase import PluginBase"}],"quickstart":{"code":"from pluginbase import PluginBase\nimport os\n\n# Define a pseudo-package for your plugins\nplugin_base = PluginBase(package='my_app.plugins')\n\n# Define a source for your plugins, specifying search paths\n# In a real app, this might be a configurable path or a directory next to your main script.\nplugin_dir = os.path.join(os.path.dirname(__file__), 'plugins')\nos.makedirs(plugin_dir, exist_ok=True)\n\n# Create a dummy plugin file for demonstration\nwith open(os.path.join(plugin_dir, 'my_plugin.py'), 'w') as f:\n    f.write('def greet():\\n    return \"Hello from my_plugin!\"')\n\nplugin_source = plugin_base.make_plugin_source(\n    searchpath=[plugin_dir]\n)\n\n# To import a plugin, activate the plugin source using a 'with' statement\nwith plugin_source:\n    from my_app.plugins import my_plugin\n    print(my_plugin.greet())\n\n# Alternatively, load a plugin programmatically\nmy_other_plugin = plugin_source.load_plugin('my_plugin')\nprint(my_other_plugin.greet())","lang":"python","description":"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."},"warnings":[{"fix":"Always wrap your plugin imports in a `with plugin_source:` block or use `plugin_source.load_plugin()` for programmatic loading.","message":"Plugins 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"PluginBase 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.","severity":"gotcha","affected_versions":"All versions"},{"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`.","message":"Be 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}