A plugin framework.
Project description
Python Baukasten
Python Baukasten is an easy to use pluggable plugin framework for python. It is a result of a long period of comparing numerous python plugin frameworks, identifying their key characteristics and designing an interface which allows to develop your own plugin manager with all the features you need while providing a sane default implementation supporting the following features:
- Import of plugins from entry-points, folders, modules, packages, and classes
- Configurable automatic initialization of plugins
- Filterable custom plugin metadata definition
- Easy to manage persistent plugin manager and plugin configuration
- Dependency-, version- and update-management
Usage
This section illustrates how to use the default implementation of Python Baukasten.
app_dir = os.path.abspath(os.path.dirname(__file__))
context = baukasten.Context(app_dir=app_dir, app_name="my-app")
plugin_manager = baukasten.PluginManager(context)
By default the PluginManager searches for plugins at the following locations:
- app_dir/plugins (e.g. /path/to/application/plugins)
- xdg_data_dir/plugins (e.g. /home/user/.config/app_name/plugins)
- entry-points
Plugins are detected via the @plugin decorator which can be used on functions, classes, and methods.
It accepts arbitrary arguments which can be used to enrich the plugin with metadata.
@plugin(spam="egg", egg="spam")
def my_function():
return 42
@plugin(egg="spam")
class MyClass:
pass
class OtherClass:
@plugin(spam="egg")
def my_method(self):
return 42
TODO: derive from yet unknown class (e.g. depends on other plugin)
To retrieve the plugins the filter method can be used:
# Gather all plugins
plugins = plugin_manager.filter()
# Gather plugins filtering on metadata
plugins = plugin_manager.filter(spam="egg")
Advanced Usage
Configuration
The default implementation of Python Baukasten supports two types of persistent configurations. The
plugin manager configuration used for storing settings related how plugins are loaded and processed and plugin
configuration where individual settings of a plugin can be stored.
Hooks
When initializing the PluginManager a list of hooks can be passed:
plugin_manager = baukasten.PluginManager(context, hooks=[
PluginPreLoadHook(lambda plugins: filter(lambda plugin: plugin.__plugin_metadata.get("egg") == "spam", plugins)),
PluginInitHook(lambda plugin: plugin("parameter-1", "parameter-2", ...))
])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file baukasten-0.0.1.tar.gz.
File metadata
- Download URL: baukasten-0.0.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
732a73d94c38b69e313df9a978a8a85b079535510fe0df69b03bba5a63df5c64
|
|
| MD5 |
810ff6f4b7a989746102117138832e3c
|
|
| BLAKE2b-256 |
68b5b0ee42b59076fdc40c6069e3b6b0bfb8886142d3ee238dd56b6ac0a27b56
|
File details
Details for the file baukasten-0.0.1-py3-none-any.whl.
File metadata
- Download URL: baukasten-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d951854c604875f7fbb066f1a305da600d582d38afd562d4476c4c37dda7ee1
|
|
| MD5 |
ce3e2070b9fbafba2662e2f1e9347e15
|
|
| BLAKE2b-256 |
4d7eb0d3fdd0abbaf9dbb537eb5b7650baac573be3ef38bb50d85c2900803f7e
|