Skip to main content

fastyaml-rs

PyPI Python License

A fast YAML 1.2.2 parser and linter for Python, powered by Rust.

Important: Requires Python 3.10 or later.

Installation

pip install fastyaml-rs

Usage

import fast_yaml

# Parse YAML
data = fast_yaml.safe_load("name: test\nvalue: 123")
print(data)  # {'name': 'test', 'value': 123}

# Dump YAML
yaml_str = fast_yaml.safe_dump({"name": "test", "value": 123})
print(yaml_str)  # name: test\nvalue: 123\n

Large Integers

Decimal integers beyond the i64 range load as exact Python ints and dump back exactly. Loading such a literal with more digits than sys.get_int_max_str_digits() (4300 by default; sign and leading zeros are not counted), or dumping an int with more digits, raises CPython's ValueError; raise the limit with sys.set_int_max_str_digits(). Literals that fit i64 never hit this limit. Hex and octal integers are capped at 14284 bits (at most 4300 decimal digits) and are not subject to the limit. PyYAML reads leading-zero literals differently (0012 is octal there).

Parse Limits

Nesting depth, alias expansion and parser lookahead are capped by default. Raise or lower the caps with keyword arguments on safe_load, safe_load_all, load, load_all, and the ParallelConfig, LintConfig, and BatchConfig constructors (each config also has with_max_depth() / with_max_alias_bytes() / with_max_scan_ahead(); None resets to the default). ParallelConfig, LintConfig, and BatchConfig also accept max_input_bytes / with_max_input_bytes(). Every loader and config accepts max_documents (each config also has with_max_documents()):

fast_yaml.safe_load(text, max_depth=512, max_alias_bytes=256 * 1024 * 1024)
Option Default Range
max_depth 256 1..=512 (flow collections stop at 255 levels)
max_alias_bytes 64 MiB 1..=1 GiB
max_scan_ahead 4 Mi characters 1..=1 Gi
max_input_bytes (ParallelConfig, LintConfig, BatchConfig) 100 MiB 1..=1 GiB
max_documents 100 000 1..=10 000 000

max_scan_ahead bounds how far the parser reads past the last node it reported, which bounds parser memory (about 190x the value). A flow collection that the parser reads whole (at the document root, in a - entry, nested in another flow collection, or after a tab), so any JSON document longer than the limit, minified or pretty-printed, a single scalar, or a run of comments longer than the limit raises ValueError; raise max_scan_ahead for such input. Block YAML, key: [..] and --- [..] are not affected.

Out-of-range values raise ValueError; non-integers (including bool) raise TypeError. Depth 512 needs about 1 MiB of thread stack (up to 983 KiB measured in release builds) and can abort the process on stacks of 512 KiB or less; the default of 256 is safe. The dumper keeps a fixed depth of 256, so data parsed deeper may fail to dump. The alias budget is per stream, so parallel and batch runs can use up to workers x budget. max_input_bytes bounds work on oversized input; an in-memory source is already allocated when checked, so it is not a memory bound there. safe_load and safe_load_all reject sources over 100 MiB. max_documents caps the documents in one stream and applies even when no config is passed (safe_load and load also read the whole stream, so a source over the limit raises ValueError); dump_parallel enforces it on the input list (cannot serialize to YAML: document count exceeds N). safe_dump, safe_dump_all and dump_all take no max_documents; they are bounded by the fixed dump limits (depth 256, output size).

Sets

Floats are written with a dot and a signed exponent so YAML 1.1 readers such as PyYAML read them as floats (1e300 becomes 1.0e+300). !!set mappings load as Python set in safe_load and parse_parallel, and dump writes set and frozenset as !!set. A !!set cannot be a mapping key (raises ValueError, like any sequence or mapping key). A !!set member with a value (!!set {a: 1}) raises ValueError with its line and column, where PyYAML drops the value; a repeated << key in one mapping raises too.

Numeric Keys

YAML treats 1, true and 1.0 as three different keys, but a Python dict or set considers them equal. Instead of silently dropping one, safe_load raises ValueError with the key's line and column when a mapping or !!set holds such keys (parse_parallel raises the same error); repeating a key of the same type is still an ordinary duplicate (last value wins). This differs from PyYAML, which keeps only one of them. .nan keys collapse to a single entry, as in the Rust core.

fast_yaml.safe_load("1: a\ntrue: b\n")
# ValueError: YAML parse error: bool key true is distinct in YAML but equal as a
#   Python dict key to a key of type int at line 2, column 1

Features

  • YAML 1.2.2 compliant — Full Core Schema support
  • Fast — matches PyYAML C on small and medium files, 2-4x faster than pure-Python PyYAML
  • PyYAML compatible — load, dump, Loader, Dumper classes; dump/safe_dump no longer accept width or allow_unicode (they raise TypeError)
  • Linter — Rich diagnostics with 1-based line/column tracking (Location(line, column, offset) rejects 0); supports inline # fy: disable / disable-line / disable-file (and # yamllint ...) suppression comments
  • Parallel processing — Multi-threaded parsing for large files
  • Batch processing — Process multiple files in parallel
  • Type stubs — Full IDE support with .pyi files

Linter Configuration

Per-rule severity and options are passed through rules; the option keys are the same kebab-case keys as in the fy config file, and errors use the same messages as fy lint --config:

from fast_yaml._core import lint

config = lint.LintConfig(
    rules={
        "line-length": {"max": 120, "severity": "error"},
        "quoted-strings": {"quote-type": "double", "required": True},
        "document-start": {"present": True},
        "duplicate-key": "warning",
    },
)
diagnostics = lint.lint("a: 1\n", config)

# Unknown rules, option keys, wrong types and invalid severities raise ValueError
lint.LintConfig(rules={"quoted-strings": {"quote-type": "singel"}})

The rules patch is applied first, then the keyword arguments you set (max_line_length, indent_size, and require_document_* / allow_duplicate_keys when True; False changes nothing), then disabled_rules (which always wins); so indent_size=2 beats rules={"indentation": {"spaces": 4}}. An omitted max_line_length keeps the default 80 and an omitted indent_size leaves the width consistent (the indent_size property is then None), as for lint(source) without a config (a rules patch can replace both); max_line_length=None (or {"line-length": {"max": None}}) removes the line length limit.

Batch Processing

Process multiple YAML files in parallel:

from fast_yaml._core import batch

# Parse multiple files
result = batch.process_files(
    [
        "config1.yaml",
        "config2.yaml",
        "config3.yaml",
    ]
)
print(f"Processed {result.total} files, {result.failed} failed")

# With configuration
config = batch.BatchConfig(workers=4, indent=2)
result = batch.process_files(paths, config)

Format Files

# Dry-run: get formatted content without writing
results = batch.format_files(["config.yaml"])
for result in results:
    match result:
        case batch.FormatResult.Formatted(path=path, content=content):
            print(f"{path}: {len(content)} bytes")
        case batch.FormatResult.Failed(path=path, error=error):
            print(f"{path}: {error.kind} {error.message}")

# In-place: format and write back
result = batch.format_files_in_place(["config.yaml"])
print(f"Changed {result.changed} files")

BatchConfig Options

Option Default Description
workers Auto None = auto, 0 = sequential, 1-128 = worker threads (larger values raise ValueError)
max_input_bytes 100 MiB Maximum file size, 1..=1 GiB
indent 2 Indentation width
max_depth 256 Maximum nesting depth, 1..=512 (process_files and format_files)
max_alias_bytes 64 MiB Alias-expansion budget per file, 1..=1 GiB (process_files only)
max_scan_ahead 4 Mi Characters the parser may read past the last node, 1..=1 Gi
max_documents 100 000 Maximum documents per file, 1..=10 000 000

format_files applies max_depth, max_scan_ahead and max_documents and ignores max_alias_bytes. indent must be 1..=9; other values raise ValueError instead of being clamped.

BatchResult

result = batch.process_files(paths)
print(f"Total: {result.total}")
print(f"Success: {result.success}")
print(f"Changed: {result.changed}")
print(f"Failed: {result.failed}")
print(f"Duration: {result.duration_ms}ms")
print(f"Files/sec: {result.files_per_second()}")

for path, error in result.errors():
    print(f"Error in {path}: {error.kind} {error.message}")

Documentation

See the main repository for full documentation.

License

Licensed under either of Apache License, Version 2.0 or MIT License at your option.

Metadata

Release files for fastyaml-rs 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastyaml-rs 0.8.0
File Size Uploaded Provenance Actions
fastyaml_rs-0.8.0.tar.gz 731.5 kB With provenance Details for fastyaml_rs-0.8.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for fastyaml-rs 0.8.0
File Actions
fastyaml_rs-0.8.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for fastyaml_rs-0.8.0-cp310-abi3-win_amd64.whl
fastyaml_rs-0.8.0-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details for fastyaml_rs-0.8.0-cp310-abi3-musllinux_1_2_x86_64.whl
fastyaml_rs-0.8.0-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details for fastyaml_rs-0.8.0-cp310-abi3-musllinux_1_2_aarch64.whl
fastyaml_rs-0.8.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for fastyaml_rs-0.8.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
fastyaml_rs-0.8.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for fastyaml_rs-0.8.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
fastyaml_rs-0.8.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for fastyaml_rs-0.8.0-cp310-abi3-macosx_11_0_arm64.whl
fastyaml_rs-0.8.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for fastyaml_rs-0.8.0-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 12.4 MB

Release files / fastyaml_rs-0.8.0.tar.gz

Download URL fastyaml_rs-0.8.0.tar.gz
Size 731.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c71572cee40c1a3de9008b0568a04b23bcc29b1be36f53d971945b6382cadbb6
BLAKE2b-256 checksum
How to use checksums
c377551f879cd44220a83fe890b662fc3b5f82e7c79378632d0380e51518a159
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / fastyaml_rs-0.8.0-cp310-abi3-win_amd64.whl

Download URL fastyaml_rs-0.8.0-cp310-abi3-win_amd64.whl
Size 1.7 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
7036ef9c46a57f5d5a541ea53bd31dd38a93efd940ec5e514be8baec84c403b9
BLAKE2b-256 checksum
How to use checksums
c978517aba9a886dc83c6bad3c082b8400ee62a4d27237678543beab417d1080
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / fastyaml_rs-0.8.0-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL fastyaml_rs-0.8.0-cp310-abi3-musllinux_1_2_x86_64.whl
Size 1.9 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
7bf34834916979262944ff79860ed0d269d13b3042812471598f38c0f8bcbaf7
BLAKE2b-256 checksum
How to use checksums
0874bdc3b4807a0ca5f2f216305c4c33a054062868aaa4156e9a4046b12dd0be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / fastyaml_rs-0.8.0-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL fastyaml_rs-0.8.0-cp310-abi3-musllinux_1_2_aarch64.whl
Size 1.7 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
3515ff40103293e1fb29a2be7cfe183811ce576c74a8749880b50426d6356cb4
BLAKE2b-256 checksum
How to use checksums
3bd5aedcd9fd7714f6282b4ed5c5c4edc153bcf09338a712ca829c06afdf7c3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / fastyaml_rs-0.8.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL fastyaml_rs-0.8.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.7 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
63869ecc60e35d9ec0a8628ec987788668c255f60065a7c99851927702ba91d7
BLAKE2b-256 checksum
How to use checksums
7ac7b37d912f749fc52c696b06ca1dd469a1494cee2efda7081e3c2f5eee539e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / fastyaml_rs-0.8.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL fastyaml_rs-0.8.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 1.6 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
4e0815f51745dec94781760b59010dd4053f18a7c0c545599b678c6899647ad7
BLAKE2b-256 checksum
How to use checksums
fc5abc43353c8982a708b56cb84e395f4630ea9635aae89a5dba83f8a9aefb16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / fastyaml_rs-0.8.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL fastyaml_rs-0.8.0-cp310-abi3-macosx_11_0_arm64.whl
Size 1.5 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c84661d874f1d796b8fad232d28d31bd3703ecac9e111456ccef17b1661547af
BLAKE2b-256 checksum
How to use checksums
914fcb24c0745f9df5c4a49e7345a9f0976a75e4ed3f46045b22e095aa0d98a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / fastyaml_rs-0.8.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL fastyaml_rs-0.8.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 1.6 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
5ae678b47f4d55d88cb190cbbcad7591ae864b2a138c62f3fe8d64007e16b283
BLAKE2b-256 checksum
How to use checksums
c5e72101a75ce30152a060c1aabb76fe5de75b0d939b4bd9d7092f1347f50f54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Security for fastyaml-rs 0.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for fastyaml_rs-0.8.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page