Skip to content

YAMLRocks vs oyaml

oyaml is not a separate YAML implementation. It is a small shim that imports PyYAML, registers ordered-dict representers and constructors, and re-exports PyYAML’s entire API. You use it as import oyaml as yaml. Its one job was preserving mapping key order, which mattered before Python 3.7. Since then, dicts are ordered by the language and modern PyYAML already keeps insertion order, so oyaml adds essentially nothing.

Everything oyaml does, PyYAML does. Its speed, its YAML 1.1 semantics, its comment handling (none), its safety story, all of it is PyYAML’s, because it is PyYAML underneath. So the real comparison is YAMLRocks vs PyYAML, and it applies here unchanged.

Featureoyaml (= PyYAML)YAMLRocks
Distinct implementationNo (PyYAML)Yes (Rust extension)
Preserves key orderYes (its point)Yes
YAML 1.2 by defaultNoYes
Comment preservationNoYes
Round-trip (byte-for-byte)NoYes
Native !includeNoYes
JSON Schema validationNoYes
Speed (parse)baseline~104x faster
Speed (dump)baseline~107x faster

YAMLRocks vs oyaml on reading and writing: YAMLRocks is about two orders of magnitude faster, because oyaml is PyYAML underneath.

YAMLRocks preserves mapping key order as a matter of course, the same as any modern dict. There is nothing to add a shim for.

import yamlrocks
yamlrocks.loads(b"z: 1\na: 2\nm: 3\n")
# {'z': 1, 'a': 2, 'm': 3} source order, always

There is no scenario where oyaml is preferable to plain PyYAML on a supported Python, and none where it beats YAMLRocks. If you are on oyaml today, you are on PyYAML with a patch that no longer does anything; move straight to YAMLRocks for YAML 1.2, comment-preserving round-trip, native includes, schema validation, and one to two orders of magnitude more speed.