Skip to main content

A YAML 1.2 subset parser built for speed, written in Rust.

Project description

TurboYAML

Subset of YAML 1.2, built for parsing speed. A Rust parser with Rust and Python bindings.

Valid TurboYAML is always valid YAML 1.2. The reverse need not hold — so parse with TurboYAML and fall back to a full YAML parser when you hit something it deliberately doesn't support.

Why

TurboYAML trades YAML's full feature richness for speed, while keeping a useful, real-world feature set alive. On typical config and data it parses roughly 25–45× faster than PyYAML's libyaml C extension, producing native Python objects (dict / list / str / int / float / bool / None) directly — no intermediate tree.

Profile turboyaml (Python) PyYAML (libyaml) speedup
Flat records 9.4M lines/s 372k lines/s 25×
Deep tree 4.1M lines/s 111k lines/s 37×
Inline flow collections 1.5M lines/s 32k lines/s 47×
Block scalars 7.2M lines/s 238k lines/s 30×
Mixed (nested + flow + blocks) 3.0M lines/s 90k lines/s 33×

Measured on one machine over a randomized corpus that includes quoted/escaped scalars and block scalars; reproduce with cargo run --release --features gen --bin perf_test && python perf_test.py. Speedup is the relative metric; absolute throughput varies with document complexity, but both parsers see the same corpus.

Install

pip install rs-turboyaml

The PyPI distribution is rs-turboyaml; the import name is turboyaml.

Usage

Python

import turboyaml

obj = turboyaml.load(text)   # → dict / list / str / int / float / bool / None

# Options (both default False):
#   strict=True          → raise ParseError on duplicate mapping keys
#   yaml_1_1_bools=True  → yes/no/on/off/y/n become bool (YAML 1.1 parity)
obj = turboyaml.load(text, yaml_1_1_bools=True)

Fall back to a full parser when a document uses something TurboYAML doesn't cover. Catch the base TurboYamlError so the fallback also triggers on the handful of valid-YAML constructs (e.g. multi-line scalars) that surface as ParseError:

try:
    obj = turboyaml.load(text)        # fast path
except turboyaml.TurboYamlError:      # UnsupportedFeatureError or ParseError
    import yaml
    obj = yaml.safe_load(text)        # full parser is the authority

This is safe because TurboYAML never silently returns data that differs from a full parser — for anything it can't handle it raises (checked in CI by a differential against PyYAML on unsupported constructs).

Rust

let value = turboyaml::parse(input)?;

Supported

  • Block mappings and sequences, arbitrarily nested — including a sequence value indented at the same column as its mapping key (key: then - item, the common real-world form)
  • Compact notation — - key: value, - - nested
  • Scalar type inference: null/~, booleans, integers (decimal / 0x / 0o), floats (incl. .inf / .nan), strings
  • Quoted strings (single line) — double-quoted with the YAML 1.2 escape set (\n, \t, \", \uXXXX, …) and single-quoted (literal, '' escape)
  • Flow collections[1, 2], {a: 1} — single-line, nestable
  • Block scalars| literal and > folded, with + / - chomping and explicit indentation indicators (|2, >3)
  • # comments
  • Any scalar type as a mapping key (42:, True:, null:)
  • Optional duplicate-key rejection — load(text, strict=True) / parse_strict

Notable differences from full YAML 1.2

  • Indentation is spaces in multiples of two — no tabs, no odd widths.
  • Core-schema booleans by default: the three YAML 1.2 spellings of each — true/True/TRUE and false/False/FALSE — are bool; any other casing (tRuE) and the YAML 1.1 words yes/no/on/off/y/n are strings. Pass yaml_1_1_bools=True to opt into full YAML 1.1 boolean parity (those tokens become bool, matching ruamel.yaml's 1.1 resolver).
  • Quoted strings are single line — for multi-line text, use a block scalar.
  • One document per stream; UTF-8 only, no BOM.

Not supported

These raise a typed UnsupportedFeatureError — distinct from a malformed-input ParseError — so the fallback pattern above can recover them cleanly:

  • Anchors and aliases — &anchor, *alias
  • Tags — !!str, !custom
  • Merge keys (<<:) and explicit/complex keys (? key)
  • Document markers (---, ...) and directives (%YAML)

Multi-document streams and multi-line quoted/plain scalars are also out of scope (for multi-line text, use a block scalar). These (and the items above) raise rather than silently mis-parse, so the fallback recovers them.

Status

Alpha, but extensively validated. Correctness rests on layered, independent checks, all run in CI:

  • Unit + integration tests — hand-written fixtures plus generator round-trips
  • A randomized differential fuzz against PyYAML — 70k+ documents, 0 mismatches
  • A boundary differential proving TurboYAML raises (never silently diverges) on unsupported constructs — the guarantee that makes the fallback safe
  • Exact YAML 1.1 boolean parity with ruamel.yaml (for yaml_1_1_bools=True)
  • The official YAML test suite — the supported subset matches its expected output; see docs/yaml-test-suite.md for the conformance breakdown

See spec.md for the normative specification.

Built with PyO3 + maturin.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rs_turboyaml-0.2.1.tar.gz (88.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rs_turboyaml-0.2.1-cp38-abi3-win_amd64.whl (629.7 kB view details)

Uploaded CPython 3.8+Windows x86-64

rs_turboyaml-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (259.8 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

rs_turboyaml-0.2.1-cp38-abi3-macosx_11_0_arm64.whl (654.4 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

rs_turboyaml-0.2.1-cp38-abi3-macosx_10_12_x86_64.whl (654.5 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file rs_turboyaml-0.2.1.tar.gz.

File metadata

  • Download URL: rs_turboyaml-0.2.1.tar.gz
  • Upload date:
  • Size: 88.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for rs_turboyaml-0.2.1.tar.gz
Algorithm Hash digest
SHA256 d7c5947e0e477fe18205dd0eb7627d80a1ed8cc1997ed40c08e8f2c2e47cf64d
MD5 4a5004bfbd39c01602e1b873e0ee79cb
BLAKE2b-256 bf648e34f53d1b6098556fc04c7b71c832a51555abb84645dd2cf3a8fff89a84

See more details on using hashes here.

File details

Details for the file rs_turboyaml-0.2.1-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: rs_turboyaml-0.2.1-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 629.7 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for rs_turboyaml-0.2.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9420bec49b4a2db57682c4657ed1d6ebb23dbaab8efc5856cb59ad5b29e15049
MD5 0e6bc7f7766507f84ec16dc57535af5f
BLAKE2b-256 d668dca3668041250b8fb5516bb78e54ee8560a184c301df437c4c8d00cb6f67

See more details on using hashes here.

File details

Details for the file rs_turboyaml-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rs_turboyaml-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d8f35c757e7eb848a05e0ec8dde9f947baef300c4d362d6d7fd24e30fab779d0
MD5 ab442a79193108961d7e453dc8b1eb1c
BLAKE2b-256 f66a27ebaa9a290f7edf08af00afadfd9c0f978deb63cd88bda430102091a7f4

See more details on using hashes here.

File details

Details for the file rs_turboyaml-0.2.1-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rs_turboyaml-0.2.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c68168b28a55cbdd93b61adf58019f07c271ae5891ca0b9c21424700a9477dc3
MD5 145a96c269017f6be042862a8178d4d0
BLAKE2b-256 4d8637c237feba4d162ed03c992063b40d087651bed57240bdd2e3f5525bde70

See more details on using hashes here.

File details

Details for the file rs_turboyaml-0.2.1-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for rs_turboyaml-0.2.1-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 25aa0d407d5a9b767c1a639ddb89450a2685e2c4c326e00c9c86977510142260
MD5 93ec5dd32108e55ace73a9cddc01e895
BLAKE2b-256 fbb2a66d47e8543a207708a0ac52232bd0b890b9c70b1cab92d8b8b66a881410

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page