ruamel.yaml — the only production-ready Python library for round-trip YAML editing with comment preservation.
| Metric | Value |
|---|---|
| Downloads | ~155M/month |
| Maintainers | 1 (Anthon van der Neut) |
| Dependent packages | 3,080 |
| Latest release | v0.19.1 (Jan 2026) |
| Hosting | SourceForge/Mercurial |
| Community fork | ruyaml (stalled, no releases 12+ months) |
- Bus factor = 1. Single maintainer with no governance structure.
- PEP 625 crisis. Maintainer signaled potential inability to continue uploading to PyPI due to namespace package naming requirements.
- Hostile contribution model. SourceForge/Mercurial hosting makes PRs/community contribution nearly impossible.
- Failed fork. ruyaml (pycontribs) was created specifically to address these risks and has itself stalled.
- No alternative. PyYAML does not support round-trip editing or comment preservation. There is no production-ready substitute.
yamlsmith — verified available on PyPI.
A modern Python library for YAML 1.2 parsing and emitting with full round-trip fidelity: comments, ordering, formatting, and whitespace are preserved through load/modify/dump cycles.
- Scanner/Tokenizer — Stream-based YAML 1.2 tokenizer that captures comments and whitespace as metadata tokens.
- Parser — Produces an event stream (similar to SAX) from tokens, attaching comment metadata.
- Composer — Builds a document tree (node graph) from the event stream, with anchor/alias resolution.
- Representer — Maps Python objects to YAML nodes, preserving type information.
- Constructor — Maps YAML nodes back to Python objects.
- Emitter — Serializes the node graph back to YAML text, replaying preserved comments and formatting.
- Public API — Simple
load(),dump(),load_all(),dump_all()functions plus aYAMLclass for configuration.
- Pure Python, zero dependencies. No C extensions, no Rust. Simple
pip install. - YAML 1.2 only. No YAML 1.1 legacy support (boolean
yes/no/on/offquirks). - Round-trip by default. The primary API preserves comments and formatting. Safe-load semantics by default (no arbitrary Python object construction).
- Type-annotated. Full PEP 561 type stubs, mypy-clean.
- Python 3.10+.
from yamlsmith import YAML
yaml = YAML()
# Round-trip load and dump
data = yaml.load(text)
yaml.dump(data, stream)
# Convenience functions
from yamlsmith import load, dump, load_all, dump_all
data = load(text) # round-trip mode
text = dump(data) # preserves commentsComments attach to the nearest node:
- Pre-comments: Lines before a mapping key or sequence item.
- Inline comments:
# commenton the same line as a value. - Post-comments: Trailing comments after a block.
- Document-level: Comments before
---or after....
Comments are stored as metadata on the node objects, not in a separate side-channel.
- Core YAML 1.2 scanner, parser, composer, emitter with comment preservation
- Python object construction/representation (dict, list, str, int, float, bool, None, datetime, binary)
- Round-trip API (
YAMLclass + convenience functions) - Anchor/alias support
- Multi-document support (
load_all/dump_all) - Flow style vs block style preservation
- Comprehensive test suite (YAML Test Suite compliance)
- PyPI package with PEP 561 type stubs
- README with migration guide from ruamel.yaml
- YAML 1.1 compatibility mode
- Custom Python object serialization (no
!!python/object) - C extension acceleration
- Schema validation