jinjyaml.representer module

class jinjyaml.representer.Representer(tag: str)[source]

Bases: object

Representer for jinja2.Template tags.

When dumping an object into a YAML string, this class converts Data objects to their string representation.

To add the representer to a PyYAML dumper, use the following code:

representer = jinjyaml.Representer("j2")  # Note: No "!" here!
yaml.add_representer(Node, representer)

Attention

  • The tag name passed to the Representer constructor MUST NOT include the leading “!”. This is because PyYAML automatically adds the “!” when registering the representer.

  • Ensure that Node is the correct type for the objects you want to represent.

Parameters:

tag (str)

tag: str

YAML tag name for include statement

Attention

Custom YAML tag’s name starts with "!". But we MUST NOT put a "!" at the beginning here, because yaml.add_representer() will add the symbol itself.