Skip to main content

pyyaml-zig

Fast, safe YAML for Python. A drop-in for PyYAML.

pip install pyyaml-zig
import pyyaml_zig as yaml

with open("config.yaml") as f:
    config = yaml.safe_load(f)

Why use it

  • 37 times faster than PyYAML. A 5 MB file loads in 35 ms. PyYAML takes 1.3 seconds with its C loader and 6 seconds without it. Writing is 13 times faster.
  • A drop-in for PyYAML. Change the import and code written for PyYAML runs: load(f, Loader=yaml.SafeLoader), safe_load, dump, the loader and dumper names, and PyYAML's error classes. Its loaders read YAML 1.1 exactly as PyYAML does.
  • Correct. It runs on yaml.zig, which passes the whole official YAML test suite.
  • Safe by default. No tag can run code or build arbitrary objects. Alias bombs and deep nesting are capped. A mapping with the same key twice is an error, not a value silently thrown away.
  • No YAML 1.1 surprises in new code. safe_load reads YAML 1.2: country: no stays the string "no", and only true and false are booleans.
  • Other threads keep running. Parsing happens outside Python's global interpreter lock.
  • Nothing to compile. Wheels for Linux, macOS and Windows, on x86_64 and arm64, for Python 3.9 and later.

Speed

A 4.9 MB file of config records, loaded, then the data written back, with identical results:

Load Write
pyyaml-zig 35 ms 56 ms
PyYAML with libyaml (CSafeLoader, CSafeDumper) 1,266 ms 753 ms
PyYAML, pure Python (SafeLoader, SafeDumper) 5,994 ms 2,626 ms
json, the same data as JSON 16 ms 15 ms

PyYAML handles each value one Python call at a time. pyyaml-zig parses and writes in Zig, and builds or reads the Python objects directly.

Use

import pyyaml_zig as yaml

doc = yaml.safe_load("name: web\nports: [80, 443]\n")
# {'name': 'web', 'ports': [80, 443]}

for doc in yaml.safe_load_all(open("stream.yaml")):
    ...

try:
    yaml.safe_load("a: 1\na: 2\n")
except yaml.YAMLError as e:
    print(e)                    # a mapping cannot have two equal keys
                                #   in "<unicode string>", line 2, column 1
    print(e.problem_mark.line)  # 1 (from 0, as in PyYAML)

safe_load takes a string, bytes (UTF-8, UTF-16 or UTF-32), or an open file. An empty stream is None.

Writing:

print(yaml.safe_dump({"name": "web", "ports": [80, 443], "enabled": "yes"}))
# enabled: 'yes'
# name: web
# ports:
# - 80
# - 443

with open("out.yaml", "w") as f:
    yaml.safe_dump(config, f)

safe_dump quotes any string a reader would take for something else, so 'yes' stays a string even for YAML 1.1 readers like PyYAML. Keys are sorted, as in PyYAML; sort_keys=False keeps your order. default_flow_style, indent, width, explicit_start and encoding work as in PyYAML. Text is written as UTF-8, as with allow_unicode=True.

Dates and datetimes are written as PyYAML writes them, plain: 2001-12-14, 2001-12-14 21:59:43.100000-05:00.

Aliases work as in PyYAML: an alias is the same object as its anchor, and an alias inside its own anchor makes a cycle. Merge keys (<<: *defaults) are applied, as PyYAML applies them.

Options:

  • schema="yaml11" reads YAML 1.1 as PyYAML does: yes is True, 0755 is 493, and 2001-12-14 is a datetime.date. Use it for files written for PyYAML. "json" and "failsafe" (every scalar a str) are there too; the default is "core", YAML 1.2.
  • merge_keys=False reads << as an ordinary key.
  • max_depth=256 is how deep a document may nest, or data be written.

Switching from PyYAML

Change the import and leave the rest:

import pyyaml_zig as yaml  # was: import yaml

with open("config.yaml") as f:
    config = yaml.load(f, Loader=yaml.SafeLoader)  # or CSafeLoader, FullLoader

try:
    data = yaml.safe_load(text)
except yaml.scanner.ScannerError as e:
    print(e.problem_mark.line)

load with any of PyYAML's loaders reads as PyYAML does: YAML 1.1 (yes is True, 0755 is 493, dates are datetime), merge keys applied, and a key given twice keeping its last value. !!set, !!binary, !!omap and !!pairs build what PyYAML builds. The tests hold it to PyYAML's own results on the YAML test suite and on 20,000 generated scalars; where they differ, PyYAML departs from the YAML spec.

dump writes as PyYAML's SafeDumper does, document markers and all. Errors are PyYAML's classes, yaml.scanner.ScannerError, yaml.constructor.ConstructorError and the rest, each with its problem_mark. A syntax error is both a ScannerError and a ParserError, so code catching either catches it.

Every loader is safe. FullLoader, UnsafeLoader and Loader read as SafeLoader does: a !!python/... tag is a ConstructorError, never an object.

How it differs from PyYAML

  • safe_load reads YAML 1.2. yes, no, on and off are strings, 0777 is the number 777 (write 0o777), and dates stay strings. schema="yaml11", or load with a PyYAML loader, reads them as PyYAML does.
  • safe_load refuses duplicate keys. PyYAML keeps the last one, and so does load.
  • No custom tags. add_constructor, add_representer and the rest raise NotImplementedError, and a tag with no constructor is a ConstructorError.
  • Writing takes dict, list, tuple, str, int, float, bool, None, date and datetime. Sets and bytes, which PyYAML writes with !!set and !!binary, are a RepresenterError, as is a datetime in flow style. default_style, canonical, version and tags are not supported.
  • No anchors when writing. An object that appears twice is written twice, and data that contains itself is an error.
  • Merged keys come last. With merge keys, a mapping's own keys come first in the dict, then the merged ones; PyYAML puts the merged ones first. The values are the same.
  • No lower layers. scan, parse, compose and emit are not there.

License

MIT. Built on yaml.zig.

Metadata

Release files for pyyaml-zig 0.3.0

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

Built distributions (wheels)

Table of built distributions (wheels) for pyyaml-zig 0.3.0
File Actions
pyyaml_zig-0.3.0-cp39-abi3-win_arm64.whl CPython 3.9 abi3 Windows ARM64 Details for pyyaml_zig-0.3.0-cp39-abi3-win_arm64.whl
pyyaml_zig-0.3.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for pyyaml_zig-0.3.0-cp39-abi3-win_amd64.whl
pyyaml_zig-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.musllinux_1_1_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64, Linux musl 1.1+ x86-64 Details for pyyaml_zig-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.musllinux_1_1_x86_64.whl
pyyaml_zig-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.musllinux_1_1_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64, Linux musl 1.1+ ARM64 Details for pyyaml_zig-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.musllinux_1_1_aarch64.whl
pyyaml_zig-0.3.0-cp39-abi3-macosx_13_0_x86_64.whl CPython 3.9 abi3 macOS 13.0+ x86-64 Details for pyyaml_zig-0.3.0-cp39-abi3-macosx_13_0_x86_64.whl
pyyaml_zig-0.3.0-cp39-abi3-macosx_13_0_arm64.whl CPython 3.9 abi3 macOS 13.0+ ARM64 Details for pyyaml_zig-0.3.0-cp39-abi3-macosx_13_0_arm64.whl

Total release size: 1.0 MB

Release files / pyyaml_zig-0.3.0-cp39-abi3-win_arm64.whl

Download URL pyyaml_zig-0.3.0-cp39-abi3-win_arm64.whl
Size 165.0 kB
Tags CPython 3.9 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
ae4c0cbab4ce77068c7bfaa030cabd007cecbc47401ceb0baddc3bdb1e79d46d
BLAKE2b-256 checksum
How to use checksums
85342e600b0961e5659a902f29545001e70d9e2934c80c096da4d3aa85a50b95
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 14, 2026.

Transparency log

Release files / pyyaml_zig-0.3.0-cp39-abi3-win_amd64.whl

Download URL pyyaml_zig-0.3.0-cp39-abi3-win_amd64.whl
Size 201.9 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
aa562e723ec40881860dab5c61726940135f91759afe59b6e88e7b5bf2999e7c
BLAKE2b-256 checksum
How to use checksums
1ad2177c6d3721f04da6eb8685db93d5972074182c05d46fd6ebab34a22dbf64
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 14, 2026.

Transparency log

Release files / pyyaml_zig-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.musllinux_1_1_x86_64.whl

Download URL pyyaml_zig-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.musllinux_1_1_x86_64.whl
Size 173.7 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 Linux musl 1.1+ x86-64 abi3
SHA-256 checksum
How to use checksums
a6128a7260d60fbfc9be1480c735f9dab1d70760f484e5a900b8aa2d79515cc5
BLAKE2b-256 checksum
How to use checksums
b26628be36fb7d362f101e24f92fdcfcaf13aea95933c5fd1feb8b46eccb993e
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 14, 2026.

Transparency log

Release files / pyyaml_zig-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.musllinux_1_1_aarch64.whl

Download URL pyyaml_zig-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.musllinux_1_1_aarch64.whl
Size 167.2 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 Linux musl 1.1+ ARM64 abi3
SHA-256 checksum
How to use checksums
c716be8a553f3dd76453d46b0bed371cddfb66d4855ff48a542e7d76650fd713
BLAKE2b-256 checksum
How to use checksums
325d338370b4acbbdc77615149aab4808efd132210756908b855ed3b7aa83609
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 14, 2026.

Transparency log

Release files / pyyaml_zig-0.3.0-cp39-abi3-macosx_13_0_x86_64.whl

Download URL pyyaml_zig-0.3.0-cp39-abi3-macosx_13_0_x86_64.whl
Size 170.4 kB
Tags CPython 3.9 abi3 macOS 13.0+ x86-64
SHA-256 checksum
How to use checksums
7b983fa541c9ff03966c791855d6eb8579a26206e3cbcbeced066bb1b705ce23
BLAKE2b-256 checksum
How to use checksums
afffe08b6436f35d1fed9f334f0ebeb5540541b3f94d8011464e53bf0ad712ed
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 14, 2026.

Transparency log

Release files / pyyaml_zig-0.3.0-cp39-abi3-macosx_13_0_arm64.whl

Download URL pyyaml_zig-0.3.0-cp39-abi3-macosx_13_0_arm64.whl
Size 161.9 kB
Tags CPython 3.9 abi3 macOS 13.0+ ARM64
SHA-256 checksum
How to use checksums
3714fe835328eb41730ee685628a3de3073fd38a0f867eb8eb9f37c73757f7d0
BLAKE2b-256 checksum
How to use checksums
2fb0d6faa02c36777c725ca78ca08d238d5e3a25638fb058f799d56e892cc05f
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 14, 2026.

Transparency log

Security for pyyaml-zig 0.3.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 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for pyyaml_zig-0.3.0-cp39-abi3-win_arm64.whl

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 14, 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.

Release history Release notifications | RSS feed

This release

0.3.0 This release

6 release files Full provenance

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