os_helper.config_utils module

Configuration Utilities

Load and validate configuration settings from multiple sources with a deterministic fallback order: 1. an explicit JSON or YAML file (or the first valid one in a folder), 2. one or more .env files merged into os.environ, 3. plain environment variables.

The helpers verify that every required key is present and raise a clear RuntimeError when none of the sources can satisfy the request.

Author:
os_helper.config_utils.get_config(keys, config_type, path=None, env_files=None)[source]

Load configuration settings using a fixed fallback order.

Precedence (first match wins): 1. path pointing to a JSON/YAML file (or, if a directory, the first

.json, .yaml or .yml file in it that contains all keys);

  1. one or more .env files merged into os.environ;

  2. the current process environment.

Parameters:
  • keys (List[str]) – Keys required to be present in the resolved configuration.

  • config_type (str) – Human-readable label used only in log messages.

  • path (Optional[str], optional) – Path to a configuration file or a directory containing one. If None or empty, this step is skipped.

  • env_files (Optional[List[str]], optional) – .env files to load into os.environ before reading variables. Defaults to [".env"].

Returns:

Mapping with one entry per requested key.

Return type:

Dict[str, Union[str, int, float]]

Raises:

RuntimeError – If none of the sources provide all required keys.

Example

>>> config = get_config(["host", "port"], "database", path="config.yaml")
>>> config
{'host': 'localhost', 'port': 5432}