Registry / serialization / ruamel.yaml

ruamel.yaml

JSON →
library0.19.1pypypi✓ verified 30d ago

ruamel.yaml is a YAML parser and emitter for Python that supports round-trip preservation of comments, sequence and mapping flow styles, and map key order. The current version is 0.19.1, released on March 28, 2026. It is actively maintained with regular updates.

pip install ruamel.yaml
INSTALL
IMPORT
SIG · RUAMEL.YAML
R
ruamel.yaml
serializationpythonv0.19.1
Install
2.0s avg
Import
42ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.19.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.046s · 18.8MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 2.0s · import 0.038s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

YAML
✓ import ruamel.yaml as YAML
Ensure 'ruamel.yaml' is imported as 'YAML' to access the 'YAML' class.

A basic example demonstrating how to load, modify, and save YAML data using ruamel.yaml.

import os import ruamel.yaml as YAML # Load YAML data with open(os.environ.get('YAML_FILE_PATH', 'data.yaml'), 'r') as file: data = YAML().load(file) # Modify data data['new_key'] = 'new_value' # Save YAML data with open(os.environ.get('YAML_FILE_PATH', 'data.yaml'), 'w') as file: YAML().dump(data, file)
Debug
Known issues
breakingThe 'load' method in ruamel.yaml requires a file object, not a string. Ensure you open the file before passing it to 'load'.
fix
Open the file using 'with open()' before passing it to 'load'.
affects: 0.19.1
gotchaThe 'YAML' class is case-sensitive. Using 'yaml' instead of 'YAML' will result in an AttributeError.
fix
Always import 'ruamel.yaml' as 'YAML' to access the 'YAML' class.
affects: 0.19.1
breakingThe script failed with FileNotFoundError because the specified YAML file ('data.yaml' by default or via the 'YAML_FILE_PATH' environment variable) does not exist at the expected location.
fix
Ensure the YAML file exists at the correct path relative to the script's execution directory, or verify that the 'YAML_FILE_PATH' environment variable is set to a valid, existing file path.
affects: 0.19.1
breakingThe specified YAML file could not be found at the given path. Ensure the file exists and the path is correct, or that the 'YAML_FILE_PATH' environment variable points to a valid file.
fix
Create the 'data.yaml' file in the expected location or verify the value of the 'YAML_FILE_PATH' environment variable to ensure it points to an existing YAML file.
affects: all
Errors
Common errors & fixes
AttributeError: module 'ruamel.yaml' has no attribute 'load'
Attempting to call `load()` as a top-level function directly from the `ruamel.yaml` module, which is the API for older `PyYAML` but not modern `ruamel.yaml`.
fix
Instantiate a `YAML` object and then use its `load()` method:
```python
from ruamel.yaml import YAML
yaml = YAML()
with open('your_file.yaml') as f:
    data = yaml.load(f)
```
TypeError: 'str' object cannot be interpreted as a file-like object
Passing a string (typically a file path) directly to the `yaml.load()` or `yaml.dump()` method, which expects a file-like object (e.g., from `open()`).
fix
Open the file first and pass the file object to the `load()` or `dump()` method:
```python
from ruamel.yaml import YAML
yaml = YAML()
with open('config.yaml', 'r') as f:
    data = yaml.load(f)
```
ruamel.yaml.parser.ParserError
The YAML input file contains invalid syntax, such as incorrect indentation, missing colons, or improperly structured mappings/sequences.
fix
Review the YAML file for syntax errors, paying close attention to indentation, key-value pair formatting, and proper use of lists and dictionaries.
ruamel.yaml.scanner.ScannerError
The YAML input contains lexical errors, such as illegal characters, unescaped special characters (e.g., '%' or '@' at the start of a line), or incorrect quoting.
fix
Inspect the YAML file for invalid characters, ensure proper escaping of special characters, and correct any malformed strings or flow collection syntax.
Upgrade
Version history
0.19.1latest on PyPI · released Jan 2, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources
ruamel.yaml — pip install ruamel.yaml · libregistry