Skip to content

api_compat

api_compat

Request shapes that work across every engine version pyetm targets.

Sibling of :mod:pyetm.config.curve_registry, which does the same for curve names.

Functions

saved_scenario_payload

saved_scenario_payload(attributes, base_url=None)

Build a saved scenario body the target engine can read.

2025-01 reads attributes from the top level; later engines from a saved_scenario root key. Also stamps version with the environment label, since MyETM defaults an unlabelled scenario to production.

Source code in src/pyetm/config/api_compat.py
def saved_scenario_payload(
    attributes: dict[str, Any], base_url: str | None = None
) -> dict[str, Any]:
    """Build a saved scenario body the target engine can read.

    2025-01 reads attributes from the top level; later engines from a
    ``saved_scenario`` root key. Also stamps ``version`` with the environment
    label, since MyETM defaults an unlabelled scenario to production.
    """
    body = dict(attributes)

    label = _environment_label(base_url)
    if label is not None:
        body.setdefault("version", label)

    if _targets_stable_2025_01(base_url):
        return body

    return {"saved_scenario": body}