spine.config.load.load_config

spine.config.load.load_config(config_str: str, root_dir: str | None = None, download: bool = True) Dict[str, Any][source]

Load a SPINE configuration from a YAML string.

Similar to yaml.safe_load(), but with SPINE’s advanced features: - Hierarchical includes with cycle detection - Metadata via __meta__ blocks - Override semantics with dot-notation - Collection operations (list append/remove, dict key removal) - Configurable strict modes (warn/error)

See module docstring for full configuration language spec.

Parameters:
  • config_str (str) – YAML configuration string

  • root_dir (Optional[str]) – Root directory for resolving relative include paths. Also used as the base for SPINE_CONFIG_PATH searches. If not provided, defaults to current working directory. Required if config contains __include__ directives with relative paths.

  • download (bool, default True) – If True, resolve !download tags by downloading files. If False, preserve !download tags as unresolved values.

Returns:

Loaded and merged configuration

Return type:

Dict[str, Any]

Raises:

Examples

Simple string config:

>>> config_str = """
... io:
...   reader:
...     batch_size: 32
... """
>>> config = load_config(config_str)
>>> print(config['io']['reader']['batch_size'])
32

String config with includes (requires root_dir):

>>> config_str = """
... include: base.yaml
... model:
...   name: resnet
... """
>>> config = load_config(config_str, root_dir="/path/to/configs")

For loading from files, use load_config_file():

>>> config = load_config_file("config.yaml")

Or equivalently:

>>> with open("config.yaml") as f:
...     config = load_config(f.read())

See also

load_config_file

Load configuration from a file path