Questions tagged [ruamel.yaml]

ruamel.yaml is a YAML 1.2 loader/dumper library for Python, with round-trip preservation of comments, tags and flow style. It is a superset of the PyYAML package. Use this tag for issues with features or installation of that are ruamel.yaml specific.

ruamel.yaml is a YAML 1.2 loader/dumper package for Python. It was originally a derivative of Kirill Simonov’s PyYAML 3.11. Apart from supporting the YAML 1.2 from 2009, and not just the YAML 1.1 specification from 2005, it includes bugfixes and enhancements for round-tripping (i.e. load, modify, dump):

  • preservation of comments and style
  • preservation of anchor names
  • preservation of merges

ruamel.yaml also includes routines to analyse sequence indentations and control over block style sequences dumping.

Installation on most systems can be done from PyPI using:

pip install ruamel.yaml

or on modern Debian and derivatives like Ubuntu 16.04 with:

sudo apt-get install python-ruamel.yaml

The source for the package can be found on bitbucket.

286 questions
3
votes
1 answer

dump the yaml to a variable instead of streaming it in stdout using ruamel.yaml

I am not able to find a way to dump the YAML to a variable in ruamel.yaml; With PyYAML, i could able to achieve the same like below: with open('oldPipeline.yml','r') as f: data = yaml.load(f, Loader=yaml.FullLoader) a = yaml.dump(data) But…
Rohith
  • 785
  • 2
  • 10
  • 24
3
votes
2 answers

Is 'yes' really an alias for 'true' according to the YAML 1.1 spec? The 1.2 spec?

I'm trying to debug an issue, and it boils down to... >>> import yaml as pyyaml >>> import ruamel.yaml as ruamel >>> ruamel.load("x: yes") == ruamel.load("x: true") False >>> pyyaml.safe_load("x: yes") == pyyaml.safe_load("x: true") True There are…
jberryman
  • 15,764
  • 4
  • 39
  • 77
3
votes
2 answers

Yaml end ("...") always dumped even if yaml.explicit_end=False

I am wondering if this is really bug or intention, but anyway. Why dumping single value always includes explicit YAML end? import sys from ruamel.yaml import YAML yaml=YAML() yaml.explicit_end=False yaml.dump(1, sys.stdout) Produces 1 ... Can the…
jorel
  • 33
  • 4
3
votes
2 answers

How to change an anchored scalar in a sequence without destroying the anchor in ruamel.yaml?

When using ruamel.yaml version 0.15.92 with Python 3.6.6 on CentOS 7, I cannot seem to update the value of an anchored scalar in a sequence without destroying the anchor itself or creating invalid YAML from the next dump. I have attempted to…
seWilliam
  • 89
  • 7
3
votes
2 answers

Configuring ruamel.yaml to allow duplicate keys

I'm trying to use the ruamel.yaml library to process a Yaml document that contains duplicate keys. In this case the duplicate key happens to be a merge key <<:. This is the yaml file, dupe.yml: foo: &ref1 a: 1 bar: &ref2 b: 2 baz: <<: *ref1 …
mamacdon
  • 2,077
  • 1
  • 13
  • 14
3
votes
1 answer

ruamel condensing comments and injecting 0x07

Given the following code: from ruamel.yaml import YAML yaml = YAML() with open(filename) as f: z = yaml.load(f) yaml.dump(z, sys.stdout) And the following file: a: > Hello. World. When is a space character (0x20), produces the…
Isaac
  • 15,652
  • 4
  • 54
  • 79
3
votes
2 answers

Safe dumping and loading of defaultdict with ruamel.yaml

I'm trying to (de-)serialize classes that have collections.defaultdict properties with ruamel.yaml in Python (3.6+ in my case). This would be a minimal example that I would like to get to work: from collections import defaultdict import…
3
votes
1 answer

how to explicitly write two references in ruamel.yaml

If I have multiple references and when I write them to a YAML file using ruaml.yaml from Python I get: <<: [*name-name, *help-name] but instead I would prefer to have <<: *name-name <<: *help-name Is there an option to achieve this while writing…
math
  • 1,548
  • 2
  • 18
  • 43
3
votes
3 answers

Use Mypy with Ruamel.yaml

I am attempting to use MyPy with modules that use ruamel.yaml and Mypy cannot find ruamel.yaml even though Python has no problem finding it. I am puzzled because I can't find a module called YAML.py or class called YAML either, even though these…
Jonathan
  • 1,917
  • 1
  • 23
  • 35
3
votes
1 answer

Updating a yaml file with the contents of another one

Setup: I have two YAML files: one huge with tags and aliases, and the other one small with some key value pairs from the big one. I'm using python2.7. Problem: I want to update values in the big one with the values present in the small…
3
votes
1 answer

ruamel.yaml: clarification on typ and pure=True

I am trying to understand what typ and pure=True mean in the ruamel.yaml Python library. I've read the documentation here. So far, I've understood that typ='safe' uses a safe loader which omits YAML tags parsing in YAML (they can lead to arbitrary…
Dmitry Figol
  • 113
  • 4
3
votes
1 answer

ImportError when ruamel.yaml is installed in a custom folder

I am facing a similar situation to the questions asked here: Python Import error on installing ruamel.yaml in custom directory I am aware that we will want to use some form of python environment isolation mechanism like virtualenv to create isolated…
Nelson
  • 31
  • 2
3
votes
2 answers

Can ruamel.yaml encode an enum?

The following is not working for me, with Python 3.4.7, ruamel.yaml version 0.15.35: import sys import enum import ruamel.yaml from ruamel.yaml import yaml_object yaml = ruamel.yaml.YAML() @yaml_object(yaml) class Speed(enum.IntEnum): Reverse…
pourhaus
  • 407
  • 4
  • 9
3
votes
1 answer

How to create a custom yaml mapping dumper for ruamel.yaml?

I'm trying to make a custom YAML dumper/loader for some configuration objects. For simplicity, assuming we want to dump a object of class Hero to a hero.yml file. The example which works with default dumper/loader class Hero: yaml_tag = '!Hero' …
soar0x48
  • 499
  • 3
  • 15
3
votes
1 answer

How to use representer in older version ( version <= 0.11) of ruamel.yaml

ruamel.yaml.RoundTripRepresenter.add_representer(type(None), represent) Works fine in the 0.14.X version of ruamel.yaml package How to use same functionality in older version ( <= 0.11 ) of ruamel.yaml package or alternative way to use in previous…
1 2
3
19 20