ruamel.yaml

0.19.1 · active · verified Sat Mar 28

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.

Warnings

Install

Imports

Quickstart

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)

view raw JSON →