Skip to content

Public API and configuration

The supported top-level imports are declared in r2x_sienna.__all__. Source links point to current main; for an installed release use tagged source.

ExportContract and source
SiennaConfigParser settings; fields.
SiennaExporterConfigExport settings with required output_path; fields.
SiennaParserContext-bound PSY JSON parser; implementation.
SiennaExporterJSON/HDF5 exporter; implementation.
SiennaUpgrader, SiennaVersionDetectorSchema migration and version reading; implementation.

Both parser and exporter use the core Plugin.from_context(ctx) class method and run(*, ctx=None) method. run() returns the updated context and raises PluginError if a lifecycle hook returns an error. The parser supplies context.system; the exporter consumes it and writes files. Core lifecycle source defines ordering and failure handling.

These are the package-specific settings. Inherited settings and validation are defined by r2x-core.

FieldMeaning
json_pathstr | None, default None; needed for ordinary disk input.
model_yearint | list[int] | None, default None.
system_namestr | None, default None; parsed system uses Sienna when unset.
system_base_powerBase MVA, defaults to 100.0 on parser and exporter.
scenarioDefaults to base.
skip_validationParser flag, defaults to false.
modelsModule tuple, defaults to ("r2x_sienna.models",).
output_pathOptional on SiennaConfig; required string on SiennaExporterConfig.

Inspect the installed schema rather than assuming current defaults apply to an older release:

>>> from r2x_sienna import SiennaConfig, SiennaExporterConfig
>>> assert "properties" in SiennaConfig.model_json_schema()
>>> assert "properties" in SiennaExporterConfig.model_json_schema()

Component definitions live in r2x_sienna.models. Topology, generation, branches, loads, services, costs, attributes, enums, and units describe the PSY serialization model. These definitions do not guarantee compatibility with every PowerSystems.jl release. Follow Python usage for a complete context example.

SiennaParser.from_context(ctx: PluginContext[ConfigT]) -> Plugin[ConfigT]
SiennaExporter.from_context(ctx: PluginContext[ConfigT]) -> Plugin[ConfigT]
plugin.run(*, ctx: PluginContext[ConfigT] | None = None) -> PluginContext[ConfigT]

These parser/exporter classes inherit these methods from the Core lifecycle. from_context binds configuration, system and store; run executes the normal hook order. A parser produces ctx.system; an exporter requires an input System and returns a context after writing files. A hook returning Err becomes a PluginError, not an Err returned by run.

Configuration classes are Pydantic models. Invalid types or a missing required field raise validation errors during construction, before plugin execution. Inspect model_json_schema() from your installed package when generating a UI or validating YAML. Package fields listed above do not replace inherited Core options.

SiennaVersionDetector().read_version(folder_path: Path) -> str | None
SiennaUpgrader(path: Path).upgrade(
*,
current_version: str | None = None,
target_version: str | None = None,
strategy: VersionStrategy | None = None,
upgrade_type: UpgradeType = UpgradeType.FILE,
) -> Result[Path, str]

read_version returns a detected version or None. upgrade returns a path on success or an error string in Result; it does not return PluginContext. Use UpgradeType.SYSTEM for the JSON-system transformations shown in Python usage. This API can rewrite input files. The parser-facing upgrade path can also migrate legacy metadata in referenced HDF5 storage. See upgrader source.

SiennaExporter.output_path resolves the required configuration string to a Path. Its on_validate hook creates missing output parents. A separate DataStore constructor still requires an existing directory; create it before the context. should_export_time_series is an instance attribute defaulting to True; set it before run() for JSON-only output. It is not an exporter configuration field.

Serialization skips unsupported component types when serialize_component_to_psy(component) returns None. Successful file creation therefore does not establish that every input object was exported. Inspect counts and parser/exporter logs and load the result in the target Julia environment. For model vocabulary use the model catalog; for units and per-unit assumptions use units.