pyaml - Pretty YAML Dumper

26.2.1 · active · verified Thu Apr 09

pyaml is a PyYAML-based module designed to produce more human-readable and aesthetically pleasing YAML-serialized data. It provides enhanced defaults for indentation, key sorting, and block-style formatting. The current version is 26.2.1, and it maintains a moderate release cadence, with updates typically several times a year to reflect PyYAML changes or minor enhancements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `pyaml.dump` to write YAML data to a file-like object (like `sys.stdout`) and `pyaml.dumps` to get the formatted YAML as a string. pyaml automatically applies its 'pretty' formatting defaults, including sorted keys and sensible indentation.

import pyaml
import sys

data = {
    'name': 'Alice',
    'age': 30,
    'isStudent': False,
    'courses': [
        {'title': 'Math', 'credits': 3},
        {'title': 'History', 'credits': 4}
    ],
    'address': {
        'street': '123 Main St',
        'city': 'Anytown',
        'zip': '12345'
    }
}

# Dump to stdout with pretty formatting
print('--- Pretty YAML Output (to stdout) ---')
pyaml.dump(data, sys.stdout)

# Or get as a string
yaml_string = pyaml.dumps(data)
print('\n--- Pretty YAML Output (as string) ---')
print(yaml_string)

view raw JSON →