Skip to main content

Fast YAML parser for Python with C++/SIMD backend

Project description

pyfastyaml

PyPI version

pyfastyaml — Fast YAML parser for Python with C++/SIMD backend. 100–300× faster than PyYAML and ruamel.yaml. API compatible with PyYAML for typical config use cases (Kubernetes, Ansible, CI, Docker Compose).

Features

  • High performance: C++17 implementation with AVX2 SIMD on x86 — orders of magnitude faster than pure-Python parsers
  • PyYAML compatible API: loads(s), load(fp) — drop-in replacement for config loading
  • Types: dict, list, str, int, float, bool, null, nested structures
  • Indentation: 2-space (preferred), 4-space, tabs

Installation

pip install pyfastyaml

Requires Python 3.10+ and a C++ compiler with C++17 support.

Usage

import pyfastyaml

# Parse string
data = pyfastyaml.loads("""
key: value
nested:
  inner: 42
items:
  - a
  - b
""")
# {'key': 'value', 'nested': {'inner': 42}, 'items': ['a', 'b']}

# Parse file (path or file-like object)
data = pyfastyaml.load("config.yaml")

API matches PyYAML for common cases:

# Drop-in replacement
import pyfastyaml as yaml  # instead of import yaml
data = yaml.loads(yaml_string)
data = yaml.load("config.yaml")

Benchmark

Parsing time (μs, lower is better):

Size pyfastyaml PyYAML ruamel pyfastyaml vs PyYAML
Small (~200 B) ~2 ~229 ~377 ~112× faster
Medium (~1.5 KB) ~7 ~1,034 ~1,777 ~141× faster
Large (~15 KB) ~66 ~11,153 ~19,040 ~170× faster
Realworld ~5 ~841 ~1,544 ~161× faster

Run benchmarks:

pip install pytest-benchmark PyYAML ruamel.yaml
pytest tests/test_benchmark.py -v --benchmark-only

PyYAML Compatibility

pyfastyaml produces the same result as yaml.safe_load() for block-style YAML typical of configs. Compatibility tests included in tests/test_pyyaml_compat.py.

MVP Limitations

pyfastyaml targets config-style YAML (K8s, Ansible, CI, Docker Compose). Not supported:

  • Flow syntax: [a, b, c], {a: 1, b: 2} — use block style instead
  • Multiline strings: | (literal), > (folded)
  • Anchors and aliases: &anchor, *alias
  • Custom tags
  • Multi-document (---)

Supported: block mappings, block sequences, scalars, comments, quoted strings, 2/4-space and tab indentation.

Development

pip install -e ".[dev]"
python setup.py build_ext --inplace
pytest tests/

Benchmark commands:

pytest tests/test_benchmark.py -v --benchmark-only
pytest tests/test_benchmark.py -v --benchmark-only --benchmark-autosave
pytest tests/test_benchmark.py -v --benchmark-only --benchmark-compare

Publishing (maintainers)

pip install build twine
python -m build
python -m twine upload dist/*

License

MIT

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

pyfastyaml-0.1.0b2.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

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

pyfastyaml-0.1.0b2-cp312-cp312-win_amd64.whl (77.6 kB view details)

Uploaded CPython 3.12Windows x86-64

File details

Details for the file pyfastyaml-0.1.0b2.tar.gz.

File metadata

  • Download URL: pyfastyaml-0.1.0b2.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for pyfastyaml-0.1.0b2.tar.gz
Algorithm Hash digest
SHA256 8b954f20d923877f38c0c87fddf97244446b93a6326a7c65e1897e34dbabe526
MD5 0fb8b2013bd6677ece8bc27423acaa32
BLAKE2b-256 a45a5288f3a7b7c1b5174aa712d07ccda213c0caf449e29fa5a2ca2b17d08f19

See more details on using hashes here.

File details

Details for the file pyfastyaml-0.1.0b2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pyfastyaml-0.1.0b2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1bcb58886f3e2d2e9224eb0746b73ba41404da19909f9646c63cd06bbdbea139
MD5 9a2c5aef36a253c051c9f9da06d3e534
BLAKE2b-256 5a80ae3ca9310eb6bc5db647138ac62bbf9c7af1a42bc1f9bc2f3601cf9605f9

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