yaml_include.data module#

class yaml_include.data.Data(urlpath, flatten=False, sequence_params=<factory>, mapping_params=<factory>)[source]#

Bases: object

A dataclasses.dataclass() to store a YAML include statement.

Parameters:
flatten: bool = False#

Whether to flatten sequence objects parsed from multiple matched YAML files.

  • Only available when multiple files are matched.

  • Each matched file must have a Sequence object at the top level, otherwise a TypeError exception will be raised.

Example

Consider the following YAML:

items: !include "*.yaml"

If each file matching *.yaml contains a sequence object at the top level, the parsed and loaded result will be:

items: [
    [item 0 of 1st file, item 1 of 1st file, ..., item n of 1st file],
    [item 0 of 2nd file, item 1 of 2nd file, ..., item n of 2nd file],
    # ...
    [item 0 of nth file, item 1 of nth file, ..., item n of nth file],
]

This results in a 2-dimensional array because the YAML content of each matched file is treated as a member of the list (sequence).

However, if the flatten parameter is set to true, like:

items: !include {urlpath: "*.yaml", flatten: true}

the result will be:

items: [
    item 0 of 1st file, item 1 of 1st file, ..., item n of 1st file,
    item 0 of 2nd file, item 1 of 2nd file, ..., item n of 2nd file,
    # ...
    item 0 of nth file, item 1 of nth file, ..., item n of nth file,
]
mapping_params: Mapping[str, Any]#

mapping parameters of the YAML include statement

sequence_params: Sequence[Any]#

sequence parameters of the YAML include statement.

urlpath: str#

URL/path of the YAML include statement

urlpath can be either absolute (e.g., /usr/src/Python-1.5/*.yml) or relative (e.g., ../../Tools/*/*.yml) and can contain shell-style wildcards.

We support "**", "?", and "[..]". We do not support "^" for pattern negation. The maxdepth option is applied to the first "**" found in the path.

Warning

Using the "**" pattern in large directory trees or with remote files may consume a significant amount of time.