Configuration

Configuration singleton for YAML config with merge and environment overrides.

The redup_servicekit.config module contains:

class ConfigSingleton[source]

Bases: object

Singleton for loading and merging YAML configuration.

Supports deep merge of additional YAML files or dicts, and override of config values from environment variables. Use ___ (triple underscore) in env names for nesting; use __ (double) for spaces in key names. Comma-separated env values become lists.

Example:

>>> from pathlib import Path
>>> from redup_servicekit.config import ConfigSingleton
>>> ConfigSingleton.load(Path("/config/config.yaml"))
>>> ConfigSingleton.merge(Path("/config/config.local.yaml"))  # if exists
>>> ConfigSingleton.inject_os_envs()
>>> config = ConfigSingleton.get()
classmethod load(config_path)[source]

Load configuration from a YAML file.

Parameters:

config_path (str or path-like) – Path to a .yaml file.

Returns:

The loaded config as a dict.

Return type:

dict

Raises:

ValueError – If the path does not exist or is not a .yaml file.

classmethod get()[source]

Return the current configuration dict.

Returns:

The config dict.

Return type:

dict

Raises:

ValueError – If configuration has not been loaded.

classmethod merge(config)[source]

Merge another YAML file or dict into the current config (deep merge).

Parameters:

config (str, path-like, or dict) – Path to a YAML file or a dict to merge in.

Raises:

ValueError – If config not initialized or path does not exist.

classmethod inject_os_envs()[source]

Override config values from environment variables.

Env names like section___subsection___key map to nested keys; __ in a segment is replaced by space in the key name. Comma-separated values become lists. Only keys already present in the config are overridden.