Skip to main content

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

Project description

FastYAML

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 FastYAML PyYAML ruamel FastYAML 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

FastYAML 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

FastYAML 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.0b1.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.0b1-cp312-cp312-win_amd64.whl (77.5 kB view details)

Uploaded CPython 3.12Windows x86-64

File details

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

File metadata

  • Download URL: pyfastyaml-0.1.0b1.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.0b1.tar.gz
Algorithm Hash digest
SHA256 8871bac22ce1eed4e5ad2571fb5caf66e6701400e5ac449312936a2cca7f9098
MD5 a1bb16042afddfcca41e5c1cfee377b1
BLAKE2b-256 d6a177427eaabcfd95a9e8c86e2686e21738d6307dc2903d9b91fa4baf0ae54d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfastyaml-0.1.0b1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d1c58a03101cc866c667b273baa7ae77a0fbcb9b11c43bfb25826a2e4233e42c
MD5 3ba03f09c325c96639c5acf2ffd233a2
BLAKE2b-256 69a775965ee699f16003cbb760b3c43fb3ab55f846c031b063ebafc7fcd52af7

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