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 insideobj
. # RenderData.source()
into a string with Jinja2 . # Parse the rendered string with the PyYAML Loader who loaded theobj
.# Render and parse:
# When
inplace
isTrue
: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
isFalse
(default):render and parse every
Data
object with corresponding parsed Python object, without modify the passed-in object;# Return the whole
obj
withData
objects replaced with corresponding rendered and parsed Python object.A single
Data
object. In this case, the function does:Render
Data.source()
into a string withJinja2
.Parse the rendered string with the PyYAML Loader who loaded the
obj
.Return the rendered and parsed Python object.
Note
When the passed-in
obj
argument is an instance ofData
, it won’t be changed, eveninplace
was set toTrue
. 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-inobj
argument’s with parsed object. WhenTrue
, theobj
should be mutable dict or list like object.
- Returns:
Final extracted Python object