Skip to main content

Fast, safe YAML parser for Python (Rust-powered)

Project description

RustyYAML ๐Ÿฆ€

Fast, safe YAML parser for Python โ€“ A drop-in replacement for PyYAML with 10-100x performance improvement.

PyPI version CI License

Features

  • โšก 10-100x faster than pure Python PyYAML
  • ๐Ÿ”’ 100% safe by default โ€“ No code execution vulnerabilities
  • ๐ŸŽฏ Drop-in replacement โ€“ Compatible with PyYAML API
  • ๐Ÿš€ Always fast โ€“ No C extension installation required
  • ๐Ÿงต Parallel loading โ€“ Parse multiple files simultaneously
  • ๐Ÿ Pure Python API โ€“ Pythonic and easy to use

Installation

pip install rustyyaml

That's it! No C compiler, no build tools needed.

Quick Start

import rustyyaml as yaml

# Parse YAML string
data = yaml.safe_load("key: value")
print(data)  # {'key': 'value'}

# Load from file
with open('config.yaml') as f:
    config = yaml.safe_load(f)

# Load from Path
from pathlib import Path
config = yaml.safe_load(Path('config.yaml'))

# Parse multiple documents
docs = yaml.load_all("""
doc: 1
---
doc: 2
---
doc: 3
""")
print(len(docs))  # 3

# Batch loading (parallel) - 5-10x faster for multiple files
results = yaml.safe_load_many([yaml1, yaml2, yaml3])

# Load entire directory
configs = yaml.load_directory('./configs', recursive=True)
for filename, data in configs:
    print(f"{filename}: {data}")

Migration from PyYAML

Option 1: Replace import

# Before
import yaml

# After
import rustyyaml as yaml

# Rest of your code works unchanged!
data = yaml.safe_load("key: value")

Option 2: Use compatibility layer

# Add this line at the top of your main file
import rustyyaml.compat

# All existing code works unchanged
import yaml
config = yaml.safe_load(open('config.yaml'))

Benchmarks

Tested on Apple M2, Python 3.11, parsing a Kubernetes manifest 5000 times:

Library Time Speedup
PyYAML (pure Python) 12.3s 1x (baseline)
PyYAML (with LibYAML) 1.8s 6.8x
RustyYAML 0.4s 30x

Batch Loading Performance

Operation Sequential Parallel Speedup
100 files 0.8s 0.2s 4x
1000 files 8.2s 1.1s 7.5x

Why RustyYAML?

The Problem

PyYAML is slow because:

  1. It's written in pure Python (interpreted, not compiled)
  2. It loops through every element sequentially
  3. It creates intermediate Python objects during parsing
  4. The C extension (LibYAML) is often missing or hard to install

The Solution

RustyYAML:

  1. Written in Rust (compiled to native code)
  2. Uses parallel processing for batch operations
  3. Zero-copy parsing where possible
  4. Always includes the fast parser (no C extension needed)
  5. Pre-built wheels for all major platforms

Safety

Unlike PyYAML, RustyYAML is secure by default:

# This would execute code in PyYAML's unsafe mode
dangerous = "!!python/object/apply:os.system ['rm -rf /']"

# RustyYAML blocks it by default
yaml.safe_load(dangerous)  # Raises YAMLError: Unsafe tag detected

# Only use unsafe_load() if you completely trust the source
yaml.unsafe_load(trusted_yaml)  # Use with caution!

API Reference

Core Functions

Function Description
safe_load(stream) Parse YAML safely (recommended)
unsafe_load(stream) Parse without safety checks
load(stream) Alias for safe_load()
load_all(stream) Parse multiple documents

File Operations

Function Description
safe_load_file(path) Load YAML from file path
load_all_file(path) Load multiple documents from file

Batch Operations

Function Description
safe_load_many(yamls) Parse list of YAML strings in parallel
unsafe_load_many(yamls) Parallel parsing without safety checks
load_directory(path, recursive=False) Load all YAML files from directory

Input Types

All loading functions accept:

  • str - YAML content as string
  • bytes - YAML content as bytes (UTF-8)
  • Path - Path to YAML file
  • File objects - Open file handles

Compatibility

โœ… Fully Supported

  • yaml.safe_load() - Drop-in replacement
  • yaml.load() - Defaults to safe mode (unlike PyYAML!)
  • yaml.load_all() - Multiple document support
  • yaml.YAMLError - Exception handling

โš ๏ธ Not Yet Supported

  • yaml.dump() / yaml.safe_dump() - Coming in v2.0
  • yaml.YAMLObject - Custom object serialization
  • Custom constructors/representers

Error Handling

from rustyyaml import YAMLError

try:
    data = yaml.safe_load(invalid_yaml)
except YAMLError as e:
    print(f"Parse error: {e}")

Development

Building from source

# Clone the repository
git clone https://github.com/yourusername/rustyaml
cd rustyaml

# Install development dependencies
pip install maturin pytest

# Build and install in development mode
maturin develop

# Run tests
pytest tests/ -v

# Run Rust tests
cargo test

# Run benchmarks
cargo bench

Project Structure

rustyaml/
โ”œโ”€โ”€ Cargo.toml              # Rust dependencies
โ”œโ”€โ”€ pyproject.toml          # Python packaging
โ”œโ”€โ”€ src/                    # Rust source code
โ”‚   โ”œโ”€โ”€ lib.rs              # PyO3 module entry point
โ”‚   โ”œโ”€โ”€ parser.rs           # YAML parsing logic
โ”‚   โ”œโ”€โ”€ types.rs            # Type conversion
โ”‚   โ”œโ”€โ”€ error.rs            # Error handling
โ”‚   โ”œโ”€โ”€ safe.rs             # Safety filters
โ”‚   โ””โ”€โ”€ batch.rs            # Parallel batch loading
โ”œโ”€โ”€ python/rustyaml/        # Python wrapper
โ”‚   โ”œโ”€โ”€ __init__.py         # Public API
โ”‚   โ””โ”€โ”€ compat.py           # PyYAML compatibility
โ”œโ”€โ”€ tests/                  # Test suites
โ””โ”€โ”€ benches/                # Criterion benchmarks

Contributing

Contributions welcome! Please read our contributing guidelines before submitting a PR.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

Licensed under either of:

at your option.

Acknowledgments

Changelog

v0.1.0

  • Initial release
  • Core YAML parsing functionality
  • PyYAML API compatibility
  • Parallel batch loading
  • Safety filters for dangerous tags

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

rustyyaml-0.1.6.tar.gz (72.3 kB view details)

Uploaded Source

Built Distributions

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

rustyyaml-0.1.6-pp310-pypy310_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (481.7 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARMv7l

rustyyaml-0.1.6-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (468.8 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

rustyyaml-0.1.6-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (481.6 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARMv7l

rustyyaml-0.1.6-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (468.8 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

rustyyaml-0.1.6-pp38-pypy38_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (481.8 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARMv7l

rustyyaml-0.1.6-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (468.9 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

rustyyaml-0.1.6-pp37-pypy37_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (483.1 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARMv7l

rustyyaml-0.1.6-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (471.2 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

rustyyaml-0.1.6-cp39-abi3-win_amd64.whl (314.5 kB view details)

Uploaded CPython 3.9+Windows x86-64

rustyyaml-0.1.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (484.7 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

rustyyaml-0.1.6-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (486.8 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARMv7l

rustyyaml-0.1.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (472.7 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

rustyyaml-0.1.6-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (838.9 kB view details)

Uploaded CPython 3.9+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file rustyyaml-0.1.6.tar.gz.

File metadata

  • Download URL: rustyyaml-0.1.6.tar.gz
  • Upload date:
  • Size: 72.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rustyyaml-0.1.6.tar.gz
Algorithm Hash digest
SHA256 a190d5ad60c9a349a02161648438390a686be01ef8fe37095c815a2769f21a56
MD5 0a9ebf96fee31119777b68f25822ebdf
BLAKE2b-256 9fe7d861308f2d237484e8e1d4e3a043d1e2def1bbb8a3b00d8ee30c74b45f91

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.6.tar.gz:

Publisher: release.yml on beelal-k/rustyyaml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rustyyaml-0.1.6-pp310-pypy310_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.6-pp310-pypy310_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 70a6378e109aad9fdb5af7b512ecbaae2a6a8b7836d663ec6d90a27108433dd7
MD5 e0e75647f25359ba065afa0ba406175c
BLAKE2b-256 40a4a2881f951c2549477ae23bf2278f14f7eab2849d74b923468a477d75d974

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.6-pp310-pypy310_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl:

Publisher: release.yml on beelal-k/rustyyaml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rustyyaml-0.1.6-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.6-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ceb7a1e52a296c60b042f3b16ca9a645a64a4222308f021c84a3c0c7d1a891aa
MD5 062c19fc707f467eec9ef340fa3edc1e
BLAKE2b-256 975b24cf89aa23ba5cdae4e8094485d2e8a2a5ef1800ca0b2665770e514997b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.6-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on beelal-k/rustyyaml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rustyyaml-0.1.6-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.6-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 257d0f9ee698f43697db2f9eb9df82d8b6f64a853b9ba4be5036b7f5475ab970
MD5 25e8a057a37fc027d2b626e73e0af01c
BLAKE2b-256 d44ae60cfebb8a596816c81024b967a08c41198632baa5519f77dfde7300177b

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.6-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl:

Publisher: release.yml on beelal-k/rustyyaml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rustyyaml-0.1.6-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.6-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e00c9c5f6254e32dedc7c4ca11e33e940966a1a183dfa5b4646140a0db11fc10
MD5 74f26226f882f7d41406752f8745ccb5
BLAKE2b-256 d548c5458bd49f5bb8f2fd1c3a2e20bc7cbb968a94efa28c03493eef513670d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.6-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on beelal-k/rustyyaml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rustyyaml-0.1.6-pp38-pypy38_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.6-pp38-pypy38_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 0f75b200539207a39b758b3d0bd40f34a52b110a7d181834cb43fb72a070531d
MD5 84a82872d41f06972d476048e8d15bef
BLAKE2b-256 ff443b887bd921df21e32f6f15f56278fefbd491a9db35fe66de78bca02df46a

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.6-pp38-pypy38_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl:

Publisher: release.yml on beelal-k/rustyyaml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rustyyaml-0.1.6-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.6-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 743368c497c05209e029387a33b5839fccff95addb3499f1250924fed969288e
MD5 8ed13ecf33b5f58b653e927151b78475
BLAKE2b-256 eed67fc7f8049e630029ccae40fd9f6b5eb8617ebc8389a6eeeb5dc44cb8adb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.6-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on beelal-k/rustyyaml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rustyyaml-0.1.6-pp37-pypy37_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.6-pp37-pypy37_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 9175e71329b74e3c06f345e145fa8350b0c794350cf984494935cac52a5c7f0c
MD5 2f8d32536e772eaa7c38f9f6594f254c
BLAKE2b-256 0e794127f669d5cbc68e4521104d6119256379e2209071cf8568d24e2c0ffb00

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.6-pp37-pypy37_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl:

Publisher: release.yml on beelal-k/rustyyaml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rustyyaml-0.1.6-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.6-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b662202a5900b1fe38ebd9614efc2833d2527ca6370d077b3f0dcdb3304b1016
MD5 73c0365afd4c79fdda9b24b4606e1c0d
BLAKE2b-256 324d15b6260fc8715763e8a81e3d1b2e0ef55ea34d98d9b90475d399664d99f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.6-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on beelal-k/rustyyaml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rustyyaml-0.1.6-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: rustyyaml-0.1.6-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 314.5 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rustyyaml-0.1.6-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ae1bf20b542250398420a1fbe908593efbeee1755baf4d10f6d4621413d21806
MD5 8abc0ddab25f09fb8f289554ecc18b50
BLAKE2b-256 72888decdce4e53761834c41e40af424ae5b1fa7e5c3be9eb1dacebab31fe225

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.6-cp39-abi3-win_amd64.whl:

Publisher: release.yml on beelal-k/rustyyaml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rustyyaml-0.1.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6c9036583e13924203bccdebf874badea06bd32f673285f7e3af740c0608f177
MD5 2b8dde2e88df2c067249584e45d3e6a7
BLAKE2b-256 f7414a0559ca2ecb151b311ca0fc75ca8a742ceb6c45b1f919e8f631fb3af80e

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on beelal-k/rustyyaml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rustyyaml-0.1.6-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.6-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 53f6ea8c0f51e34cbb79e87ba0824391cd8d9623a9958c757844adb4201a17ee
MD5 77f65a4afd89d56c3f56d3f19d9595be
BLAKE2b-256 506b9a1125a96d5aec873c58e11b0807a500370390a6a101c33390b138f69afd

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.6-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl:

Publisher: release.yml on beelal-k/rustyyaml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rustyyaml-0.1.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 45ceb68b57b8e112b34a2ff697a889afa209d6144b19e621a8e600960d9b9dcc
MD5 0d9d99e1c4a5b7aa833cf8653aca9c05
BLAKE2b-256 7f03746e417be2dfc5aa5cb5789de64149beeb523f57214f71303c1844cbcf46

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on beelal-k/rustyyaml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rustyyaml-0.1.6-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.6-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 683bd2d6288c19365e0446a0f3873733beae48c96b2eb5b72d26264b2227d2c3
MD5 183cbcfafd9b7a65ac67f84760d93974
BLAKE2b-256 2f03407af3b6846f37c512688a22c534f262f9ef3b7bfdcb61a416098d79aa62

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.6-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: release.yml on beelal-k/rustyyaml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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