ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order
Homepage Repository PyPI Python
pip install ruamel.yaml==0.18.6
ruamel.yaml
is a YAML 1.2 loader/dumper package for Python.
version: | 0.15.81 |
---|---|
updated: | 2018-12-06 |
documentation: | http://yaml.readthedocs.io |
repository: | https://bitbucket.org/ruamel/ |
pypi: | https://pypi.org/project/ruamel.yaml/ |
Starting with version 0.15.0 the way YAML files are loaded and dumped is changing. See the API doc for details. Currently existing functionality will throw a warning before being changed/removed. For production systems you should pin the version being used with ``ruamel.yaml<=0.15``. There might be bug fixes in the 0.14 series, but new functionality is likely only to be available via the new API.
If your package uses ruamel.yaml
and is not listed on PyPI, drop
me an email, preferably with some information on how you use the
package (or a link to bitbucket/github) and I'll keep you informed
when the status of the API is stable enough to make the transition.
_test/test_z_data.py
_test/test_z_data.py
processes these.dict(**commented_map_instance)
and JSON
dumping works. This also allows checking with isinstance()
on dict
resp. list
.
(Proposed by Stuart Berg, with feedback
from blhsing on
StackOverflow)]
and }
instead of IndexError. (Issue reported and PR with fix
provided by Naomi Seyfer.)key
and reverse
parameter (suggested by Jannik Klemm via email)!Arg [a, {b: 1}]
yaml.brace_single_entry_mapping_in_flow_sequence=True
to force
getting [a, {b: 1}, {c: {d: 2}}]
instead of the default [a, b: 1, c: {d: 2}]
.5
(reported by Harrison Gregg)simple mappings can now be used as keys when round-tripping:
{a: 1, b: 2}: hello world
although using the obvious operations (del, popitem) on the key will fail, you can mutilate it by going through its attributes. If you load the above YAML in d, then changing the value is cumbersome:
d = {CommentedKeyMap([('a', 1), ('b', 2)]): "goodbye"}
and changing the key even more so:
- d[CommentedKeyMap([('b', 1), ('a', 2)])] = d.pop(
CommentedKeyMap([('a', 1), ('b', 2)]))
(you can use a dict instead of a list of tuples (or ordereddict), but that might result in a different order, of the keys of the key, in the output)
check integers to dump with 1.2 patterns instead of 1.1 (reported by Lele Gaifax)
python -O
optimizing away code (reported, and detailed cause
pinpointed, by Alex Grönholm)CommentedSeq
a subclass of list
. It is now
indirectly a subclass of the standard
collections.abc.MutableSequence
(without .abc if you are
still on Python2.7). If you do isinstance(yaml.load('[1, 2]'),
list)
) anywhere in your code replace list
with
MutableSequence
. Directly, CommentedSeq
is a subclass of
the abstract baseclass ruamel.yaml.compat.MutableScliceableSequence
,
with the result that (extended) slicing is supported on
``CommentedSeq``.
(reported by Stuart Berg)CommentedMap
) to fix incomplete copies of merged mappings
(reported by Will Richards){**merged-mapping}
and dict(**merged-mapping)
(reported independently by
Tim Olsson and
Filip Matzner)YAML()
as a context manager for output, thereby making it much easier
to generate multi-documents in a stream.| # some comment
)
Both needed for round-tripping multi-doc streams in
ryd.oitnb
for formatting, mypy 0.620 upgrade and conformitybuild
(reported by
Roman Sichnyi)collections
on 3.7
(issue 210, reported by Reinoud Elhorst). It was difficult to find
why tox/pytest did not report and as time
consuming to actually fix the tests.YAML.load_all(Path())
, remove StopIteration
(PR provided by Zachary Buhman,
also reported by Steven Hiscocks.sysconfig.get_config_var('Py_UNICODE_SIZE')
. (merge provided by
Marcel Bargull)register_class()
now returns class (proposed by
Mike Nerone}tox
on Python 2.7 wide and narrow, as well as
3.4/3.5/3.6/3.7/pypylibyaml
, C-extensions
compilation still needs a compiler though.None
as stream when specifying transform
parameters to
YAML.dump()
.
This is useful if the transforming function doesn't return a meaningful value
(inspired by StackOverflow by
rsaw).yaml.default_flow_style = None
(default: False
) for
for typ='rt'
.ScalarFloat
now return float
(reported by [email protected]){"in":{},"out":{}}
(reported on StackOverflow by
mjalkio
?
and :
in plain scalars if non-ambigious
(reported by nowox)yaml.boolean_representation = [u'False', u'True']
yaml_object
to replace YAMLObject.pure=True
only!)pure
attribute on YAML
useful for implementing !include tag
constructor for including YAML files in a YAML file
install ruamel.yaml[jinja2]
pathlib.Path
as "stream" parameter to all
load/dump functionsYAML
class for new API...
)
in YAML 1.2typing
while still supporting mypy
(http://stackoverflow.com/a/43516781/1307905)0o12_345_67
dumps back as
0o1_23_45_67
as the space from the last digit to the
underscore before that is the determining factor).RUAMEL_NO_PIP_INSTALL_CHECK
will suppress pip
-check.For older changes see the file CHANGES