Yapsy - Yet Another Plugin System

raw JSON →
1.12.2 verified Sat May 09 auth: no python

Yapsy is a simple, reusable plugin system for Python applications. It provides a base class for plugins and a plugin manager that discovers and loads plugins from directories. The latest version is 1.12.2, with sporadic releases.

pip install yapsy
error yapsy.IPlugin.IPlugin is not instantiated correctly
cause Trying to instantiate IPlugin base class directly or forgetting to inherit.
fix
Ensure your plugin class inherits from yapsy.IPlugin.IPlugin and implements activate()/deactivate().
error AttributeError: 'NoneType' object has no attribute 'getPluginByName'
cause PluginManagerSingleton.get() returned None because plugins were not collected yet.
fix
Call pm.collectPlugins() before trying to get a plugin by name.
gotcha Plugin constructor (__init__) is called before plugin info (name, version, etc.) is set. Do not rely on plugin metadata in __init__; use activate() instead.
fix Override activate() instead of __init__ to access plugin manager or metadata.
deprecated The use of PluginManager without arguments is deprecated in favor of PluginManagerSingleton or custom locations.
fix Use PluginManagerSingleton.get() or pass plugin_places explicitly.

Defines a plugin class, uses the singleton plugin manager to discover and activate plugins from a 'plugins' directory.

from yapsy.IPlugin import IPlugin
from yapsy.PluginManager import PluginManagerSingleton

class MyPlugin(IPlugin):
    def activate(self):
        print("Plugin activated")
    def deactivate(self):
        print("Plugin deactivated")

if __name__ == "__main__":
    pm = PluginManagerSingleton.get()
    pm.setPluginPlaces(["plugins"])
    pm.collectPlugins()
    pm.activatePluginByName("MyPlugin")
    pm.deactivatePluginByName("MyPlugin")