jinjyaml.constructor module¶
- class jinjyaml.constructor.Constructor¶
Bases:
objectConstructor class for
jinja2.TemplateYAML tags.When parsing YAML string, the class constructs template tags to
Dataobjects.Add the constructor to PyYAML Loader as below:
import yaml import jinjyaml as jy ctor = jy.Constructor() # Attention: tag name starts 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 tag starts with
"!". When we invokeyaml.add_constructor, thetagparameter MUST have a single"!"at the beginning.Content of the tag MUST be text