jinjyaml.constructor module¶
- class jinjyaml.constructor.Constructor[source]¶
Bases:
objectConstructor class for
jinja2.TemplateYAML tags.When parsing a YAML string, this class constructs template tags into
Dataobjects.To add the constructor to a PyYAML loader, use the following code:
import yaml import jinjyaml as jy ctor = jy.Constructor() # Note: Tag names start with "!" # Add to default loader yaml.add_constructor("!j2", ctor) # or: Add to CLoader yaml.add_constructor("!j2", ctor, yaml.CLoader) # or: Add to SafeLoader yaml.add_constructor("!j2", ctor, yaml.SafeLoader) # or: Add to other loaders...
Attention
Custom YAML tags must start with
"!". When invokingyaml.add_constructor, thetagparameter must include a single leading"!".The content of the tag must be text.