config
¶
Functions:
-
load_config–Load a YAML configuration file.
-
mask_sensitive_info–Mask sensitive information in the given DictConfig.
-
setup_logging–Set up logging configuration from a dict.
load_config
¶
load_config(config_path: str) -> dict[str, Any]
Load a YAML configuration file.
Supported syntax
${VAR} → If VAR not set, becomes "" (empty string) ${VAR, default} → If VAR not set, "default" is inserted literally, and then YAML type-casts it.
Behavior
- Read the entire YAML file as a raw string.
- Perform string-level substitution for ${...} patterns.
- Pass the substituted string to PyYAML, allowing YAML to determine types.
- Expand leading
~in string values into absolute home paths.
- Expand leading
This design ensures
- No custom smart-casting logic is needed.
- Default values are type-cast by YAML (10→int, false→bool, etc.).
- Environment variable values are applied before YAML parsing.
Parameters:
-
(config_path¶str) –Path to the YAML configuration file.
Returns:
-
dict[str, Any]–Parsed configuration as a Python dict with correct types.
mask_sensitive_info
¶
mask_sensitive_info(
config: dict[str, Any],
) -> dict[str, Any]
Mask sensitive information in the given DictConfig.
This function replaces the values of predefined sensitive keys (e.g., "api_key", "api_token", "password", "secret_key") with a masked string. It processes nested DictConfig recursively.
Parameters:
-
(config¶dict[str, Any]) –DictConfig to mask.
Returns:
-
dict[str, Any]–A new dictionary with sensitive values masked.
setup_logging
¶
setup_logging(logging_cfg: dict) -> None
Set up logging configuration from a dict.
Parameters:
-
(logging_cfg¶dict) –The logging configuration to apply.
Raises:
-
TypeError–If the configuration cannot be converted to a dictionary.