Skip to content

SPF is a simple plugin framework following the design principals laid out by Marty Alchin.

License

Notifications You must be signed in to change notification settings

syn54x/SimplePluginFramework

Repository files navigation

SimplePluginFramework

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.

Install

pip install simple-plugin-framework

Fundamentals Of A 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:

Declaration

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"

Registration

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

Discovery

The framework needs to be able to discover what plugins are available.

How

Discovery can happen in two ways...

  1. 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">}
  1. You can call the MyMountPoint.load() method to load plugins via entry_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">}

About

SPF is a simple plugin framework following the design principals laid out by Marty Alchin.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages