Skip to content

YAMLSource

A ConfigSource that loads values from a YAML file.

Warning

In order to use this source you must have pyyaml installed either directly or by including the "yaml" extra when installing this package (e.g. poetry install flex-config -E yaml).

Parameters:

Name Type Description Default
path pathlib.Path

a pathlib.Path to a YAML file to load.

required
path_must_exist bool

if true, the constructor will raise a RuntimeError if the provided path doesn't exist.

required

_load_file(self, file) private

Loads and parses the YAML file

Source code in flex_config\file_sources\yaml_source.py
34
35
36
37
38
39
def _load_file(self, file: TextIO) -> Dict[str, Any]:
    """ Loads and parses the YAML file """
    import yaml

    config_dict = yaml.safe_load(file)
    return config_dict