Plugins
The Kaizo plugin system provides a structured mechanism for extending functionality without modifying the core parser.
Plugins are dynamically imported, configured, and exposed as callable factories that can be invoked multiple times during execution.
Plugin System
Plugins are Python classes that subclass Plugin and are imported
from the kaizo.plugins namespace.
Unlike standard configuration entries, plugins are:
Loaded during parser initialization
Not executed immediately
Wrapped as callable factories
Executed on demand
Important
Every plugin must be importable from
kaizo.plugins.<plugin_name>.
Plugin Configuration
Plugins are registered under the top-level plugins key.
Each plugin entry defines which plugin class should be loaded and which arguments should be passed to the plugin constructor when execution occurs.
Plugin with arguments
plugins:
my_plugin:
source: MyPlugin
args:
x: 1
Plugin without arguments
plugins:
my_plugin: MyPlugin
Note
The plugin key (my_plugin) determines the module path
kaizo.plugins.my_plugin.
Plugin Loading Behavior
During parsing, Kaizo performs the following steps for each plugin:
Imports
kaizo.plugins.<plugin_name>Loads the plugin class specified by
sourceResolves plugin arguments
Wraps the plugin’s
dispatchmethod usingFnWithKwargsStores the wrapped callable for later use
Important
The plugin’s dispatch method is not called during parsing.
It is only wrapped and prepared for execution.
Plugin Invocation
Plugins are accessed using module: plugin.
task:
module: plugin
source: my_plugin
When this entry is resolved:
The wrapped
dispatchcallable is retrievedThe callable is invoked
The plugin instance is created or returned
Note
Since dispatch is wrapped using FnWithKwargs,
it may be called multiple times, depending on how it is referenced.
Calling Plugin Methods
After a plugin instance is returned, any callable method on that instance
may be invoked using the call field.
task:
module: plugin
source: my_plugin
call: run
args:
steps: 10
Execution flow:
Call wrapped
dispatch→ returns plugin instanceLook up method on the instance
Execute the method with resolved arguments
Warning
The method specified by call must exist and be callable.
Plugin Rules
All plugins must follow these rules:
Must subclass
PluginMust be importable from
kaizo.plugins.<plugin_name>Must expose a
dispatchmethoddispatchmust return a usable plugin instanceConstructor arguments must be YAML-resolvable
Tip
Plugins are ideal for managing stateful resources or reusable services that may need to be instantiated multiple times.
Execution Summary
Plugin lifecycle in Kaizo:
Plugin module is imported
Plugin class is loaded
dispatchis wrapped withFnWithKwargsDispatch is invoked on demand
Plugin instances may be created multiple times
Plugin methods are executed via
call
Note
Because dispatch is callable multiple times, plugin authors should
ensure that repeated instantiation is safe if required.