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.7.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.7-pp310-pypy310_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (482.3 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARMv7l

rustyyaml-0.1.7-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (469.0 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

rustyyaml-0.1.7-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (482.1 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARMv7l

rustyyaml-0.1.7-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (468.9 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

rustyyaml-0.1.7-pp38-pypy38_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (482.3 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARMv7l

rustyyaml-0.1.7-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (469.1 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

rustyyaml-0.1.7-pp37-pypy37_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (483.8 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARMv7l

rustyyaml-0.1.7-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (471.3 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.9+Windows x86-64

rustyyaml-0.1.7-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (484.8 kB view details)

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

rustyyaml-0.1.7-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (487.9 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARMv7l

rustyyaml-0.1.7-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.7-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (839.6 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.7.tar.gz.

File metadata

  • Download URL: rustyyaml-0.1.7.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.7.tar.gz
Algorithm Hash digest
SHA256 240bb1456fbe652915b13f9d4de5f4cec94e95d0361b20c0f54135293fd37e05
MD5 27847cb236e4b78688f0df25c44e9d82
BLAKE2b-256 17c331d37da337794c78c9847904dc160369824c1a023a892307832bf6783eb5

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.7.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.7-pp310-pypy310_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.7-pp310-pypy310_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 274397049279e9a33ebc973b317106e9ad4a39ae05fd6a4ef138a798059baf71
MD5 29ec887be818a5c0e9135e8132a64259
BLAKE2b-256 63880c11328d90c5a641d2feb62c6f3343527fba87aa0af1210442fbdf342f8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.7-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.7-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.7-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 263e94629b30b41b11b150e240f7ba22032aaa896159cdee38cfd1849c1c3926
MD5 b898242c37f71ee9e682e7bd3a1d9b5b
BLAKE2b-256 a3cc57c837a50dd53d47eee8d0e766b0d7a106c3e2aa2f3769fffe952937f010

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.7-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.7-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.7-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 64304170158053dbad4a0868b1e3f44b37ef3696fbb38e135080facf254b65a9
MD5 9dc1f8b16cd49745728bbe9d410f522a
BLAKE2b-256 fe1f34eab10b7c1fc216e6a6589476d5dbbb166196205df6e6d47e57ed833ae5

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.7-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.7-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.7-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2298d4d96a956320282b20b0575c4e23b45576df6d98213a506dc9bc2d464acf
MD5 ff7024e0d8609ece48c219dc525698ae
BLAKE2b-256 165c9df40587b3a160e26acc262203a91d936d36f2dc38f1ad16548e610313ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.7-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.7-pp38-pypy38_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.7-pp38-pypy38_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 0a2c9537a5959ee722a256a67b757d94fe45cdb459a4e966e8d89b01aab7cbd8
MD5 7c42f1221e3e37dc0a3c0d3b0eac2d17
BLAKE2b-256 403417ae0f35f479ceb47a314ab0913758e4e5cb650b2e02546690ed59342144

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.7-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.7-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.7-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 24f4904c51ff5af94c804a86263d4ece0f8c5c23d98f96be59385840ea73198a
MD5 22a923781148cfcf20b9d04c7a448df8
BLAKE2b-256 114a176c590f1c095e3d53501320f72d2e3d5be6c9a690cfdcde52545ab82369

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.7-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.7-pp37-pypy37_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.7-pp37-pypy37_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 058291e584fbeb9417887ccb224ffe0f8adea1ff561b1cb9bb5893cfe0e02f63
MD5 dc786ef6249e22b5a19fda9f15722913
BLAKE2b-256 0034b21f713498102989fde39ca3e2caa05e589adee4e7dd9e9ab8001d734c5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.7-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.7-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.7-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 79396ff6724175a954a2a1d214719fc1e5b98ee238a76f01fb33c4519196fdf1
MD5 62abb2ed256db605922fdb69d291b1e1
BLAKE2b-256 09f563b48c96124758c86ef279f59660b83179ebda0b7235a998570dd12bbeb1

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.7-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.7-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: rustyyaml-0.1.7-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.7-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2ca958f2cc4fc3877a05db156a7fe60b578831e5038a9ab0d98a86f027192873
MD5 38ed04f6c63d2b258fa2f1a7818e2b35
BLAKE2b-256 2e1d26612f8f9793f79e6ecb0c32f99d120f0216236a4d12953c3a33ff8b90f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.7-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.7-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.7-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d1b7b0716f80e8344382e173c4ab82ff7dd5761504f7364ae97ef0f412dfd43e
MD5 3acd8ef8cb2a3fbe777443fc2a2c5a3f
BLAKE2b-256 a8d723417858c7ad2c77ef0c9d8115ecad54d044f7ca7652a5ddc2eedba48eab

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.7-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.7-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.7-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 064267c40745ee99e56775104ddaaef4a53b490939ef2aae3e1f6546d23ed747
MD5 84a7aeba25f66dcad1fe8ad31e6b85c2
BLAKE2b-256 c1cc5161681929adaceb11713e30a7787914284caeae14e78c32c956e1c48b6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.7-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.7-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rustyyaml-0.1.7-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c3bafabe53e9f4f9ca0bd02acd7333b7a10f48dc46fffb7e87404619b7e9f736
MD5 58d5aec8f159c7727d269fcb13ac782c
BLAKE2b-256 94e923e4544bbca88eccb060cc726a63a792b0d7fcda89ebdd04fa83fa98cda4

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.7-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.7-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.7-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 eee114a6a44867eb3d75ca661d4902fa38bb8604de4950a3bb7a9ef339345f66
MD5 ef94b6716e01cf36dfc6de3e571ede92
BLAKE2b-256 ba99b3a14edaa2199192ff46e1e4d77500cc36d5e56ca325192006d9cf83b307

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustyyaml-0.1.7-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