Skip to content

Create and Register Plugins

A plugin consists of a configuration class and a plugin implementation.

Define a PluginConfig subclass:

>>> from r2x_core import PluginConfig
>>> from pathlib import Path
>>> class MyPluginConfig(PluginConfig):
... input_folder: Path
... year: int
>>> config = MyPluginConfig(input_folder=Path("/data"), year=2030)
>>> config.year
2030

Extend Plugin and implement lifecycle hooks:

>>> from r2x_core import Plugin, PluginConfig, PluginContext
>>> from rust_ok import Ok
>>> class MyPluginConfig(PluginConfig):
... pass
>>> class MyPlugin(Plugin[MyPluginConfig]):
... def on_build(self):
... from r2x_core import System
... return Ok(System(name="result"))
>>> config = MyPluginConfig()
>>> ctx = PluginContext(config=config)
>>> plugin = MyPlugin.from_context(ctx)
>>> result = plugin.run()
>>> result.system.name
'result'

Register plugins in pyproject.toml for automatic discovery:

[project.entry-points."r2x.parsers"]
my-parser = "my_package.plugins:MyPlugin"

The group declares the runtime role; the entry name is the CLI reference. For function transforms use r2x.transforms and an @expose_plugin function accepting System and typed configuration. The CLI worked example installs and executes both forms.