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_loadreads YAML 1.2:country: nostays the string"no", and onlytrueandfalseare 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:yesis True,0755is 493, and2001-12-14is adatetime.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=Falsereads<<as an ordinary key.max_depth=256is 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_loadreads YAML 1.2.yes,no,onandoffare strings,0777is the number 777 (write0o777), and dates stay strings.schema="yaml11", orloadwith a PyYAML loader, reads them as PyYAML does.safe_loadrefuses duplicate keys. PyYAML keeps the last one, and so doesload.- No custom tags.
add_constructor,add_representerand 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
!!setand!!binary, are a RepresenterError, as is a datetime in flow style.default_style,canonical,versionandtagsare 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,composeandemitare not there.
License
MIT. Built on yaml.zig.
Metadata
Release files for pyyaml-zig 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 1.0 MB
Release files / pyyaml_zig-0.2.0-cp39-abi3-win_arm64.whl
| Download URL | pyyaml_zig-0.2.0-cp39-abi3-win_arm64.whl |
|---|---|
| Size | 163.8 kB |
| Tags | CPython 3.9 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
b28828c679aa8f2c680ae25af9685d0907e1bb7150e28bd7c08f0950f38ec62a
|
|
BLAKE2b-256 checksum How to use checksums |
63aaf03561ceaede51839c48cf483bbdc700ad32e072f637dbb1a1d1ac14befa
|
| 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 7, 2026.
Transparency logRelease files / pyyaml_zig-0.2.0-cp39-abi3-win_amd64.whl
| Download URL | pyyaml_zig-0.2.0-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 199.8 kB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
05baa7edc3cf5a9f12b6fb64ac60cd513163ae9d9ef974c2f90dd572f68d10b2
|
|
BLAKE2b-256 checksum How to use checksums |
c9632b561be93667f0c8533400de5fea8caae586a64fc579fd587ea07a19dd35
|
| 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 7, 2026.
Transparency logRelease files / pyyaml_zig-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.musllinux_1_1_x86_64.whl
| Download URL | pyyaml_zig-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.musllinux_1_1_x86_64.whl |
|---|---|
| Size | 170.6 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 |
5e4d9c73dd4a15a65b821f393d1537d9e6c86d655cb1c96f3ff57e5b52699b41
|
|
BLAKE2b-256 checksum How to use checksums |
38e2b8a38acdaf5eca827245920e0ad0134445b70cc7e5c07dbbd7ea9ef474b3
|
| 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 7, 2026.
Transparency logRelease files / pyyaml_zig-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.musllinux_1_1_aarch64.whl
| Download URL | pyyaml_zig-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.musllinux_1_1_aarch64.whl |
|---|---|
| Size | 165.8 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ ARM64 Linux musl 1.1+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
f99da6e0c0cce3fcd2107d7019351af824d01cc4d930e8e8a2a1c53a18c864cf
|
|
BLAKE2b-256 checksum How to use checksums |
108c00d5355e5ce0a32b43787c83bd6380241b24abd3ca719aa3d2c4aa9ed6ff
|
| 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 7, 2026.
Transparency logRelease files / pyyaml_zig-0.2.0-cp39-abi3-macosx_13_0_x86_64.whl
| Download URL | pyyaml_zig-0.2.0-cp39-abi3-macosx_13_0_x86_64.whl |
|---|---|
| Size | 167.9 kB |
| Tags | CPython 3.9 abi3 macOS 13.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
63e58a27e45efd01488e7107408e7dfcefc467b95d5ec154b7358ac3b1ff01bf
|
|
BLAKE2b-256 checksum How to use checksums |
536bbafd294ce17d9db4c65cf1371a0a04809c6759402094a543d690480c4cb7
|
| 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 7, 2026.
Transparency logRelease files / pyyaml_zig-0.2.0-cp39-abi3-macosx_13_0_arm64.whl
| Download URL | pyyaml_zig-0.2.0-cp39-abi3-macosx_13_0_arm64.whl |
|---|---|
| Size | 160.5 kB |
| Tags | CPython 3.9 abi3 macOS 13.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ae3da0a16f4d4b95de0aa3c215cd228790657276fc1182d8388b92b1e2d88a0c
|
|
BLAKE2b-256 checksum How to use checksums |
a81dd5dd175613cc834f2177f6c3aa0c22c76a0afe4bbda4fbe5ab009adf58a0
|
| 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 7, 2026.
Transparency logSecurity for pyyaml-zig 0.2.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.
Attestation for pyyaml_zig-0.2.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 7, 2026.
Transparency logA 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.