Skip to content

How YAMLRocks compares

The Python YAML ecosystem has long forced a choice: PyYAML (fast with the C loader, but YAML 1.1 only, no comments, no round-trip) or ruamel.yaml (YAML 1.2 with comments and round-trip, but pure Python and slow). YAMLRocks refuses the trade-off. It is Rust-fast and round-trip capable, with native includes, schema validation, and source tracking on top.

PyYAMLruamel.yamlYAMLRocks
YAML 1.2NoYesYes
ImplementationC + PythonPure PythonRust
Parse speedC loaderslow6-10x vs PyYAML C
Dump speedC dumperslow17-19x vs PyYAML C
Comments preservedNoYesYes
Byte-for-byte round-trip (unmodified)NoCloseYes
Native !include (+ write-back)NoNoYes
JSON Schema validationNoNoYes
Source line/columnNopartialYes
Safe by default (no code exec)No (yaml.load)Yes (safe)Yes
Bytes output (no extra encode)NoNoYes
Free-threaded (nogil) safeNoNoYes

Release-build benchmarks (python bench/bench.py), showing how many times faster YAMLRocks is:

  • Parsing: ~6-10x faster than PyYAML’s C loader; ~105-141x faster than ruamel.
  • Serializing: ~17-19x faster than PyYAML’s C dumper; ~160-208x faster than ruamel.
  • Split configs with !include: ~17x faster than a PyYAML !include constructor for hundreds of files.

These are ratios, not absolute times, and they vary with payload shape and hardware. Run python bench/bench.py on your own machine to reproduce them. The performance guide explains where the speed comes from and how to measure your own workload.

The Python YAML ecosystem is larger than PyYAML and ruamel. There are newer Rust-backed parsers and pure-Python contenders too. YAMLRocks leads the field on both load and dump. Indicative wall-clock times from python bench/compare.py (release build, whole payload set, fastest first):

LibraryImplloaddump
YAMLRocksRust~1.7 ms~1.0 ms
yaml-rsRust~2.1 ms~1.3 ms
fast-yamlRust~2.9 ms~1.7 ms
py-yaml12Rust~4.0 ms~1.4 ms
ryamlRust~4.7 ms~3.4 ms
PyYAML (C)C~17.1 ms~16.1 ms
yamliumPython~71 ms~11 ms
PyYAML (pure)Python~177 ms~106 ms
oyamlPython~177 ms~106 ms
ruamel.yamlPython~260 ms~199 ms
strictyamlPython~1.38 sno dumper

Speed is only half of it. The Rust rivals differ in what they get right: yaml-rs, py-yaml12, and ryaml leave << merge keys unresolved, and yaml-rs, py-yaml12, and fast-yaml misread a bare 0777 as the integer 777. YAMLRocks is the fastest, and the only one verified against the entire official YAML test suite.

Every page carries a benchmark, a feature matrix, side-by-side code, and an honest account of where the other library fits.