Skip to content

Config helpers

The file-loading edge, for a loader that does its own parsing. Most apps want BaseAppConfig and load_app_config instead.

opennvr_app_sdk.load_yaml

load_yaml(path: str | Path) -> dict[str, Any]

Read + parse a YAML config file, requiring a mapping at the root.

Raises ValueError on a non-mapping root and lets OSError from the read propagate — callers surface both as operator-facing config errors and exit non-zero.

Source code in opennvr_app_sdk/config.py
22
23
24
25
26
27
28
29
30
31
def load_yaml(path: str | Path) -> dict[str, Any]:
    """Read + parse a YAML config file, requiring a mapping at the root.

    Raises ``ValueError`` on a non-mapping root and lets ``OSError``
    from the read propagate — callers surface both as operator-facing
    config errors and exit non-zero."""
    raw = yaml.safe_load(Path(path).read_text())
    if not isinstance(raw, dict):
        raise ValueError(f"config {str(path)!r}: root must be a mapping")
    return raw

opennvr_app_sdk.require

require(
    cfg: dict[str, Any], key: str, *, path: str = "config"
) -> Any

Fetch a required config value, rejecting missing / empty values.

path names the config source in the error message (file path or a nested-section breadcrumb like "config: cameras[0]").

Source code in opennvr_app_sdk/config.py
34
35
36
37
38
39
40
41
42
def require(cfg: dict[str, Any], key: str, *, path: str = "config") -> Any:
    """Fetch a required config value, rejecting missing / empty values.

    ``path`` names the config source in the error message (file path or
    a nested-section breadcrumb like ``"config: cameras[0]"``)."""
    value = cfg.get(key)
    if value is None or (isinstance(value, str) and not value.strip()):
        raise ValueError(f"{path}: {key!r} is required")
    return value