Plugins

Plugins in System Template are Python files stored in the _plugins folder. There are two types of plugins:

  • Global plugins: These are stored in the <filters-data>/system_template/_plugins folder and are shared across all systems.

  • Local plugins: These are stored in the <filters-data>/system_template/<system>/_plugins folder and are specific to the respective system.

Plugins are executed using the exec function, and their local scope is merged with the scope of the system. In cases where a local plugin defines functions or variables with the same name as a global plugin, the local definition takes precedence.

It is recommended to use plugins only for defining functions. Data should be defined in the _scope.json files and the global scope file of system_template. While plugins can execute arbitrary code, it is advised to limit their use to function definitions.

Upon a fresh installation of the system_template filter in your project, the default global plugins folder will contain a file named _default.py. This file defines a plugin that imports the following objects and modules from Python’s standard library:

  • math

  • random

  • uuid

  • pathlib.Path

Note

The use of plugins stands out as one of the main advantages of employing System Template over its individual modules. While using Subfunctions or JSON Template alone restricts you to the functions provided by each module, System Template allows you to extend their functionallity by adding your own functions through plugins.