Plugin Configuration

Often, plugins require some configuration before running. For example you might want to run plugin on data from a specific service, or run a specific version of your machine learning model. To configure your plugin when running it from the front-end, plugins require a config.json in the root of the plugin repository. This file contains a declarative definition, which our front-end app uses to display a configuration screen.

This module contains utilities to directly generate this config file from the plugin definition, by inferring all arguments from the plugin __init__ method. All configuration fields are textboxes by default, which can be changed to different types in the future. For a full example, see our guide on building plugins.

Usage:

create_plugin_config

create_config

create_config(plugin_cls:type)

Returns a declarative plugin configuration, inferred from the `__init__` method signature of `plugin_cls`.
This function is used internally by the `create_plugin_config` CLI. For general use, use the CLI instead.
Arguments that start with `_`, untyped arguments or arguments that are not in `ALLOWED_TYPES` are skipped.
Args:
    plugin_cls (type): A plugin class, inherited from PluginBase.
Returns:
    List[dict]: A declarative configuration definition as list of dictionaries.

create_plugin_config

create_plugin_config(metadata:"metadata.json of the plugin"='./metadata.json', tgt_file:"Filename of config file"='config.json', schema_file:"Filename of exported plugin schema"='schema.json')

Creates a plugin configuration definition from the arguments of your plugin class.
Configuration arguments are inferred from the arguments of your plugin `__init__` method.
Arguments that start with `_`, untyped arguments or arguments that are not in `ALLOWED_TYPES` are skipped.
All generated fields are "textbox" by default, in the future our front-end will support more
types of fields.
Args:
    metadata (Param, optional): Location of the "metadata.json" file,
        Defaults to "./metadata.json"
    tgt_file (Param, optional): File the config definition is saved to.
        Defaults to "config.json".

Example

As example, we create a test plugin with various configuration arguments. The create_config method is called on the plugin, and generates a declarative configuration field for each plugin argument. Note that arguments that start with a _, and untyped arguments are skipped in the annotation.

class MyPlugin(PluginBase):
    def __init__(
        self,
        my_arg: str,
        my_str: str = None,
        my_int: int = None,
        my_float: float = None,
        my_bool: bool = None,
        unannotated=None,
        _private=None,
        **kwargs
    ):
        super().__init__(**kwargs)
    def run(self):
        pass
    def add_to_schema(self):
        pass
config = create_config(MyPlugin)
for c in config:
    print(f'{c["display"]} ({c["data_type"]})') 
Skipping unannotated parameter `unannotated`
My Arg (Text)
My Str (Text)
My Int (Integer)
My Float (Real)
My Bool (Bool)