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 · Quickstart · 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.

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)

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.7.0.tar.gz (73.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.7.0-py3-none-any.whl (89.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: r2x_core-0.7.0.tar.gz
  • Upload date:
  • Size: 73.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.7.0.tar.gz
Algorithm Hash digest
SHA256 1d0f3a9c707aeb64b217e11a6582b198034ae2c7c84767d909d585f4e3be0e43
MD5 085ce61199a840504d63aed66bc7a47a
BLAKE2b-256 4b7172226a7b7d84ad6dfacdccbeb1613862fc4f9f34f3a47a5f6fb77899c1d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for r2x_core-0.7.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.7.0-py3-none-any.whl.

File metadata

  • Download URL: r2x_core-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 89.2 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.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c71fc23c0cc0f586e586a91f15d54b46810c691f6b05723eb9881963aad2153
MD5 a219ae3be66670245284de911726801a
BLAKE2b-256 ed866e4f5a6ad88266d73bfeea60134fc2e5217eafebc2b83fd1e05ce6d572eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for r2x_core-0.7.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

0.8.0

2 files

This release

0.7.0 This release

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