Skip to content

YAMLRocks vs py-yaml12

py-yaml12 is a Rust-backed YAML 1.2 parser (built on the saphyr crate) with genuinely good first-class custom-tag handling. It is a clean data parser, and its tag support is a real strength. But it is a one-way parser: it does not edit YAML, resolve includes, or validate against a schema, and YAMLRocks is both more complete and faster.

Featurepy-yaml12YAMLRocks
Comment-preserving round-tripNoYes (byte-for-byte)
Native !include + writebackNoYes
JSON Schema validationNoYes (line-numbered)
Source line/columnNoYes (annotated mode)
Custom tag handlingYes (first-class)Yes
Verified vs the YAML suiteClaims fullYes, in full
Multi-document streamsYesYes
Merge keys (<<)NoYes
ImplementationRust (saphyr)Rust (own scanner/emitter)
Speed (parse / dump)baseline~2.4x / ~1.4x faster

py-yaml12’s tag handling is legitimately nice: a Yaml(value, tag) wrapper and handlers= callables transform tagged nodes at parse time. YAMLRocks matches that (a tags= registry and a tag_handler) and then adds the whole configuration-editing layer py-yaml12 has no answer for:

  • Comment-preserving round-trip. Edit a value and re-emit with comments, anchors, and formatting intact; unmodified documents come back byte-for-byte. py-yaml12 reads data but cannot write an edited file back.
  • Native !include with file-aware write-back across split configurations.
  • JSON Schema validation with line-numbered errors.
  • Annotated mode with the source line and column on every node.

See custom tags, round-trip editing, includes, and schema validation.

Both are Rust extensions built for correctness and speed. YAMLRocks is faster on both directions.

YAMLRocks vs py-yaml12 on reading and writing: YAMLRocks is faster on both loads and dumps.

Operationpy-yaml12YAMLRocksYAMLRocks is
Reading~4.0 ms~1.7 ms~2.4x faster
Writing~1.4 ms~1.0 ms~1.4x faster

Both aim at YAML 1.2, and py-yaml12 states it targets the test suite. YAMLRocks runs that suite in CI on every change (load, round-trip, and canonical result all checked), and it also resolves merge keys and the 1.2 scalar edges py-yaml12 does not:

import yamlrocks
# Merge keys: YAMLRocks folds the base in; py-yaml12 leaves `<<` as a literal key.
yamlrocks.loads(b"base: &b\n timeout: 30\nsvc:\n <<: *b\n name: api\n")
# {'base': {'timeout': 30}, 'svc': {'timeout': 30, 'name': 'api'}}
# `0777` is a string in YAML 1.2; py-yaml12 returns the number 777.
yamlrocks.loads(b"mode: 0777")
# {'mode': '0777'}

For turning trusted YAML 1.2 data into Python objects with rich custom tags, py-yaml12 is a solid, MIT-licensed choice, and its tag API is genuinely good. If you never edit YAML, resolve includes, or need schema validation, it fits.

Choose YAMLRocks when you want that same clean 1.2 parsing and tag handling plus the editing toolkit around it, comment-preserving round-trip, includes, schema validation, source locations, verified correctness including merge keys, and more speed.