jinjyaml.functions module

jinjyaml.functions.extract(obj, env: Environment | None = None, context: Mapping[str, Any] | None = None, inplace: bool = False)

Recursively render and parse template tag objects in a YAML doc-tree.

The obj parameter may be:

  • A mapping or sequence object returned by a PyYAML Loader. In this case, the function does:

    # Recursively search Data objects inside obj. # Render Data.source() into a string with Jinja2 . # Parse the rendered string with the PyYAML Loader who loaded the obj .

    # Render and parse:

    # When inplace is True:

    In-place replace every Data object with corresponding parsed Python object.

    In this case, obj should be mutable or it can not be changed.

    # When inplace is False (default):

    render and parse every Data object with corresponding parsed Python object, without modify the passed-in object;

    # Return the whole obj with Data objects replaced with corresponding rendered and parsed Python object.

  • A single Data object. In this case, the function does:

    1. Render Data.source() into a string with Jinja2.

    2. Parse the rendered string with the PyYAML Loader who loaded the obj.

    3. Return the rendered and parsed Python object.

    Note

    When the passed-in obj argument is an instance of Data, it won’t be changed, even inplace was set to True. However, return value is the pared object.

  • Other scalar objects returned by a PyYAML Loader. In this case, the function returns obj with noting changed.

Parameters:
  • obj (dict, list, Data) – What already parsed by PyYAML Loader.

  • env (jinja2.Environment) – Environment for Jinja2 template rendering.

  • context (Mapping[str, Any]) – Variables name-value pairs for Jinja2 template rendering.

  • inplace (bool) – In-place replace Data inside the passed-in obj argument’s with parsed object. When True, the obj should be mutable dict or list like object.

Returns:

Final extracted Python object