LiquidBT plugins are classes that extend or modify functionality of LiquidBT.
Use a Plugin¶
To use a plugin, you need to:
- Import it at the top of your LiquidBT configuration file.
- Create an instance of the plugin's class in the
pluginslist that you pass to
- The plugin will be loaded!
Make a Plugin¶
Making a plugin is simple.
- Create a new Python package following the naming scheme
- In your
__init__.py, add this import:
from liquidbt.plugins import Plugin
- Add a
classwith the name of your plugin that extends the forementioned
Pluginclass. In this class, you can override any of the mentioned fields in the up-to-date API reference.
- Instruct your users to import and use your plugin. Easy as that.
By default, plugins only can add, but using the build plugin, you can change functionality. See Transformer Plugins.
A transformer plugin is a plugin that can change the code (not the source, the code that is compiled by setuptools).
To make a transformer, your plugin must extend a different class then typical plugins:
from liquidbt.plugins import TransformerPlugin class MyTransformer(TransformerPlugin): # ...
TransformerPlugin class extends the plugin class, so any functions you can add to
Plugins can also be added to
To actually change the code, you will need to add the
process_code(code: str) -> str method to the class. This method accepts the parameter
code, which is a multiline string of the current file being evaluated's contents. It must return the changed version of the code (also a multiline string).
If you don't need to modify the file's contents, (for example if you make a plugin that comments out all code (bear with me here), and you want to skip certain files) you can just return the
code parameter, which will ensure that your plugin doesn't change anything. But do not return
None or something like it, as the file's code will be composed of what you returned.
Dangers of Creating Transformer Plugins
TransformerPlugin class API is in LiquidBT's core package, it isn't actually implemented there (other then checking if any of the plugins are transformers, to prevent potential issues). The build plugin must be loaded before any transformers, otherwise errors will be thrown. This means instructing users to put the build plugin first in the