There are four standard typ
parameters:
rt
: (for round-trip) in this case the document is loaded in special types that preserve comments, etc., used for dumping. This is what ruamel.yaml
was created for and this is the default (i.e. what you get if you don't specify typ
). This is a subclass of the safe
loader/dumper.
safe
: this only loads/dumps tagged objects, when these are explicitly registered with the loader/dumper
unsafe
: try to load/dump everything. Classes are automatically resolved to a tag of the form !!python/object:<module>/<class>
base
: the loader/dumper from which everything is derived. All scalars are loaded as strings (even the types like integer, float, Boolean that are handled specially as mentioned in the YAML specification or the type description
For safe
, unsafe
, base
there is the faster C Loader available. If you install from the .tar.gz
file these will only get compiled during installation when the appropriate compiler is available. If they are not available, because they could not be compiled, then they cannot be used.
There is no C version of the rt
code. So it is not possible to use C libraries.
The word pure
is for when you use Python only modules. The opposite would be "tainted": Python tainted with C extension modules. There is no tainted=True
parameter. This is implicit (when possible/available, see previous paragraph) when pure=true
is not specified, as the default for pure
is False
In order to further confuse you: the above are the four basic (built-in) values for type
. If you use plug-ins you can e.g. do
yaml = YAML(typ='jinja2')
as shown in this answer
Some of the above information is available from the YAML()
docstring, little of that however made it into the package documentation, primarily as a result of lazyness of ruamel.yaml
's author.
YAML(typ="safe")
? – Bedder