class wxflow.YAMLFile(path=None, data=None)[source]

Bases: AttrDict

Reads a YAML file as an AttrDict and recursively converts nested dictionaries into AttrDict. This is the entry point for all YAML files.

wxflow.parse_yaml(path=None, data=None, encoding='utf-8', loader=<class 'yaml.loader.SafeLoader'>)[source]

Load a yaml configuration file and resolve any environment variables The environment variables must have !ENV before them and be in this format to be parsed: ${VAR_NAME}. E.g.: database:

host: !ENV ${HOST} port: !ENV ${PORT}

app:

log_path: !ENV ‘/var/${LOG_PATH}’ something_else: !ENV ‘${AWESOME_ENV_VAR}/var/${A_SECOND_AWESOME_VAR}’

Parameters:
  • path (str) – the path to the yaml file

  • data (str) – the yaml data itself as a stream

  • loader (Type[yaml.loader]) – Specify which loader to use. Defaults to yaml.SafeLoader

  • encoding (str) – the encoding of the data if a path is specified, defaults to utf-8

Returns:

the dict configuration

Return type:

Dict[str, Any]

Adopted from: https://dev.to/mkaranasou/python-yaml-configuration-with-environment-variables-parsing-2ha6

wxflow.parse_j2yaml(path: str, data: Dict, searchpath: str | List = '/') Dict[str, Any][source]

Description

Load a compound jinja2-templated yaml file and resolve any templated variables. The jinja2 templates are first resolved and then the rendered template is parsed as a yaml.

Parameters:
  • path (str) – the path to the jinja2 templated yaml file

  • data (Dict[str, Any], optional) – the context for jinja2 templating

  • searchpath (str | List) – additional search paths for included jinja2 templates

returns:

the dict configuration

rtype:

Dict[str, Any]

wxflow.save_as_yaml(data, target)[source]
wxflow.dump_as_yaml(data)[source]
wxflow.vanilla_yaml(ctx)[source]

Transform an input object of complex type as a plain type