Create and Register Plugins
A plugin consists of a configuration class and a plugin implementation.
Configuration
Section titled “Configuration”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.year2030Plugin Implementation
Section titled “Plugin Implementation”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'Entry Point Registration
Section titled “Entry Point Registration”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.
See Also
Section titled “See Also”- structure plugin directories - Directory structure
- run plugins - Using plugins