Skip to main content

r2x-core

Extensible framework for building power system model translators

image image image CI codecov Ruff Documentation

R2X Core provides the shared infrastructure for translating between power-system model formats. It gives translator authors a typed plugin lifecycle, a configuration-driven data loading layer, declarative rule mapping, unit-aware models, and versioned upgrade helpers.

Use it when you are building or extending translators for models such as ReEDS, PLEXOS, SWITCH, Sienna, or other infrasys-backed power-system workflows.

Install · Skills · Quickstart · r2x CLI · Core concepts · Documentation · Development · Roadmap · Contributing · License

Install

pip install r2x-core

Or with uv:

uv add r2x-core

R2X Core supports Python 3.11, 3.12, and 3.13.

Skill installation

This repository includes the r2x-core agent skill at skills/r2x-core/. Install it for Pi with either supported skill manager. The commands below use the canonical repository, NatLabRockies/r2x-core.

Skills CLI (npx skills)

Install globally:

npx skills add NatLabRockies/r2x-core --skill r2x-core --agent pi --global --yes

Install for the current project by omitting --global:

npx skills add NatLabRockies/r2x-core --skill r2x-core --agent pi --yes

Update one installed copy:

npx skills update r2x-core --global --yes
# For a project-scoped installation, use --project instead of --global.

List installed skills with npx skills list --global or npx skills list. The updater uses source metadata recorded by the installer; manually copied skills must be reinstalled before automatic updates can work.

GitHub CLI (gh skill)

Install globally or for the current project:

gh skill install NatLabRockies/r2x-core r2x-core --agent pi --scope user
gh skill install NatLabRockies/r2x-core r2x-core --agent pi --scope project

Check for updates, then update one skill or all managed skills:

gh skill update r2x-core --dry-run
gh skill update r2x-core
gh skill update --all

Pin a reproducible release when needed:

gh skill install NatLabRockies/r2x-core r2x-core@v0.7.0 \
  --agent pi --scope user

Edit the repository copy under skills/r2x-core/ when contributing changes. Do not patch an installed copy and expect those changes to flow back here.

Quickstart

Load model input files

DataStore manages named DataFile definitions and reads them through the configured DataReader pipeline.

from r2x_core import DataFile, DataStore, TabularProcessing

store = DataStore(path="/path/to/data")
store.add_data([
    DataFile(
        name="generators",
        relative_fpath="gen.csv",
        proc_spec=TabularProcessing(
            column_mapping={"capacity_mw": "p_max_mw"},
            filter_by={"status": "active"},
        ),
    ),
    DataFile(name="loads", relative_fpath="load.parquet"),
])

generators = store.read_data("generators")
available = store.list_data()

Use relative_fpath for files under the store root, fpath for explicit paths, and ReaderConfig(kwargs=...) when the default reader needs format-specific options such as HDF5 dataset keys.

Build a class-based translator plugin

Class plugins implement only the lifecycle hooks they need. Hooks return Ok(...) or Err(...); Plugin.run() returns the final PluginContext and raises PluginError on the first hook failure.

from rust_ok import Ok

from r2x_core import Plugin, PluginConfig, PluginContext, System


class MyModelConfig(PluginConfig):
    input_folder: str
    model_year: int
    scenario: str = "base"


class MyModelTranslator(Plugin[MyModelConfig]):
    def on_build(self):
        system = System(name=f"{self.config.scenario}_{self.config.model_year}")
        return Ok(system)


config = MyModelConfig(input_folder="/path/to/data", model_year=2030)
context = PluginContext(config=config)
plugin = MyModelTranslator.from_context(context)
result = plugin.run()

print(result.system.name)

r2x CLI

The Rust r2x CLI is the recommended orchestration layer for installed r2x-core plugins. It installs plugin packages, discovers r2x_plugin and r2x.transforms entry points, refreshes plugin metadata, and runs direct plugins or YAML pipelines. The binary is maintained in the r2x-cli repository.

Install the latest release on macOS/Linux:

curl --proto '=https' --tlsv1.2 -LsSf \
  https://github.com/NatLabRockies/r2x-cli/releases/latest/download/r2x-installer.sh | sh

On Windows PowerShell:

powershell -ExecutionPolicy Bypass -c "irm https://github.com/NatLabRockies/r2x-cli/releases/latest/download/r2x-installer.ps1 | iex"

Verify the binary and its command surface:

r2x --version
r2x --help

The published binary requires Python shared libraries at runtime. If it reports missing libpython, install a supported shared Python with uv python install 3.12. Use the published release installers or binaries only; do not build r2x from source as part of the r2x-core workflow.

Install and discover an r2x-core plugin

r2x install r2x-reeds
r2x list
r2x sync
r2x run plugin

For a local plugin package under development, run the command from that plugin's checkout. r2x-core itself is a framework package and does not expose an installable plugin entry point:

cd /path/to/my-translator
r2x install -e .
r2x sync
r2x list

Check a plugin's generated public CLI contract before running it:

r2x run plugin r2x-reeds.reeds-parser --show-help

Validate and run a pipeline

Use the CLI's validation stages before executing data translation:

r2x init
r2x run pipeline.yaml --list
r2x run pipeline.yaml --print reeds-to-sienna
r2x run pipeline.yaml reeds-to-sienna --dry-run
r2x run pipeline.yaml reeds-to-sienna --output output/system.json

Use --list to validate the pipeline name, --print to inspect resolved configuration, and --dry-run to verify ordering without translating data. Keep plugin diagnostics on stderr and translation artifacts on stdout or a durable --output path. Use set -o pipefail for streamed plugin pipelines.

The CLI's -q, -v, and -vv flags control CLI verbosity. Use --log-python or r2x log set log-python true when Python/Loguru diagnostics must be shown. See the skill's r2x CLI reference for discovery, direct execution, durable -o/-i boundaries, pipeline validation, and failure triage.

Create a function transform

For focused System -> System transformations, expose a plain function and register it through the r2x.transforms entry-point group.

from rust_ok import Ok, Result

from r2x_core import PluginConfig, System, expose_plugin


class ScaleConfig(PluginConfig):
    scale: float = 1.0


@expose_plugin
def scale_system(system: System, config: ScaleConfig) -> Result[System, str]:
    return Ok(system)
[project.entry-points."r2x.transforms"]
scale_system = "my_package.transforms:scale_system"

Core concepts

Concept What it does
Plugin / PluginContext Coordinates translator lifecycle hooks and shared pipeline state.
PluginConfig Provides typed Pydantic configuration for translators and transforms.
DataFile / DataStore Declares, reads, and processes model input files.
Rule / RuleFilter Maps source components to target components with declarative filters.
HasUnits / Unit Adds unit-aware field validation and display formatting.
UpgradeStep Applies versioned data or schema upgrade steps.

R2X Core builds on infrasys for System and Component primitives.

Documentation

Full documentation is available at natlabrockies.github.io/r2x-core, including tutorials, how-to guides, and the API reference.

Development

This repository uses uv and just for local automation.

just setup
just hooks
just test
just docs

Common tasks:

Command Purpose
just setup Install all dependency groups.
just format Format Python code with Ruff.
just lint Run Ruff checks.
just type Run ty type checks.
just test Run pytest.
just docs Build Sphinx docs.
just verify Run hooks, docstring coverage, and tests.

Roadmap

Contributing

We welcome contributions. See the contributing guide for local setup, development workflow, and review expectations.

License

R2X Core is released under the BSD 3-Clause License. See LICENSE.txt for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

r2x_core-0.8.0.tar.gz (78.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

r2x_core-0.8.0-py3-none-any.whl (94.1 kB view details)

Uploaded Python 3

File details

Details for the file r2x_core-0.8.0.tar.gz.

File metadata

  • Download URL: r2x_core-0.8.0.tar.gz
  • Upload date:
  • Size: 78.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for r2x_core-0.8.0.tar.gz
Algorithm Hash digest
SHA256 1010261b345a5b3211a018f024202219578f476ba9c2bf48364af90cea96e552
MD5 6e194d1d79f7798e8cd608d450d48a56
BLAKE2b-256 3506322b18ace8b40b475cb3a6be3a2bb69bc57e5df92970efcfb9031b390e03

See more details on using hashes here.

Provenance

The following attestation bundles were made for r2x_core-0.8.0.tar.gz:

Publisher: release.yaml on NatLabRockies/r2x-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file r2x_core-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: r2x_core-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 94.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for r2x_core-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1953e13d21c01737d3983acad61d1e106645c1ef479fac3b2f538ca497ba368d
MD5 0336504e26aed18b79d657594d2bace0
BLAKE2b-256 6baf2a1b750aaaa8088bc355d3988b802e7ce896bffe86b63e969967a9283746

See more details on using hashes here.

Provenance

The following attestation bundles were made for r2x_core-0.8.0-py3-none-any.whl:

Publisher: release.yaml on NatLabRockies/r2x-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.8.0 This release

2 files

0.7.0

2 files

0.6.0

2 files

0.5.1

2 files

0.5.0

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

0.0.11

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.3

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page