SPF is a simple, low-code, dependency free plugin framework following the design principals laid out by Marty Alchin in his blog post A Simple Plugin Framework
If you like, you can visit our Docs pages.
pip install simple-plugin-framework
SPF is a dead simple, low code, pure python plugin framework. The framework satisfies the three primary requirements for a plugin based architecture:
The framework needs to provide a mechanism for declaring a mount point for plugins
How
Declare a mount point by inheriting from spf.PluginMount
metaclass.
from spf import PluginMount
class MyMountPoint(metaclass=PluginMount):
entry_point = "my_mount_point"
The framework needs to be able to register a plugin to a declared mount point.
How
Register a mount point by inheriting from your defined MountPoint
class.
class MyPlugin(MyMountPoint):
pass
The framework needs to be able to discover what plugins are available.
How
Discovery can happen in two ways...
- If the plugin is imported, then the MountPoint discovers it:
from my_pkg import MyMountPoint
from my_plugin import MyPlugin
print(MyMountPoint.plugins)
> {'MyPlugin': <class "__main__.MyPlugin">}
- You can call the
MyMountPoint.load()
method to load plugins viaentry_points
.
Plugins can be provided to the mount points via python entry_points
. Entry points can be provided by various build tools like setuptools or poetry
from my_pkg import MyMountPoint
MyMountPoint.load()
print(MyMountPoint.plugins)
> {'MyPlugin': <class "__main__.MyPlugin">}