Skip to content

yaml_settings_source

YAML settings source module.

Classes

YamlSettingsSource

YamlSettingsSource(
    settings_cls: Type[BaseSettings], yaml_path: str
)

Bases: PydanticBaseSettingsSource

A settings source that reads configuration values from a YAML file.

Note that YAML settings that are not referenced explicitly by the pydantic-settings model will be ignored

To properly work, an environment variable with the same name as contained in ENV_SETTINGS_YAML needs to be set. Otherwise no configuration will be loaded and this settings source will silently return nothing

Attributes

loaded_configs instance-attribute
loaded_configs = load_yaml_settings(yaml_path=yaml_path)

Functions

__call__
__call__() -> Dict[str, Any]

Loads the settings YAML file and populates the settings model fields.

Returns:

  • Dict[str, Any]

    Dict[str, Any]: A dictionary containing the populated settings model fields.

get_field_value
get_field_value(
    field: FieldInfo, field_name: str
) -> Tuple[Any, str, bool]

Retrieves the value of a specific field from the loaded configurations. Note that the first configuration match found will be returned.

Parameters:

  • field (FieldInfo) –

    The field information object.

  • field_name (str) –

    The name of the field.

Returns:

  • Tuple[Any, str, bool]

    Tuple[Any, str, bool]: A tuple containing the field value, field key, and a boolean indicating whether the field is complex.

load_yaml_settings
load_yaml_settings(yaml_path: str) -> List[Dict[str, Any]]