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 loaderslow5-10x vs PyYAML C
Dump speedC dumperslow15-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: ~5-10x faster than PyYAML’s C loader; ~85-135x faster than ruamel.
  • Serializing: ~15-19x faster than PyYAML’s C dumper; ~155-210x faster than ruamel.
  • Split configs with !include: ~18x 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.

  • Coming from PyYAML and want the same safe-by-default loading, but faster, on YAML 1.2, with comments and includes? Read YAMLRocks vs PyYAML.
  • Coming from ruamel.yaml for its round-trip fidelity, but tired of pure Python speed? Read YAMLRocks vs ruamel.yaml.

Both pages carry full benchmark tables, feature matrices, side-by-side code, migration notes, and an honest “when to stick with the other library” section.