Skip to content

lava-sh/yaml-rs

Repository files navigation

yaml-rs

A High-Performance YAML parser for Python written in Rust

PyPI License Python version Implementation

Monthly downloads Github Repository size

Features

  • The fastest YAML parser in Python (see benchmarks)
  • Full YAML v1.2 spec support

Installation

# Using pip
pip install yaml-rs

# Using uv
uv pip install yaml-rs

Examples

from pprint import pprint

import yaml_rs

yaml = """\
app:
  name: service
  environment: production
  debug: false
  version: 1.3.5

  log:
    level: INFO
    file: /var/log/service/app.log
    rotation:
      enabled: true
      max_size_mb: 50

  database:
    engine: mariadb
    host: localhost
    port: 3306
    username: app_user
    password: super_secret_password
    pool_size: 10
    timeout_seconds: 30

  metadata:
    author: "John Doe"
    created_at: 2024-01-15T12:00:00Z
    updated_at: 2025-11-09T10:30:00Z
"""
pprint(yaml_rs.loads(yaml))

PyYAML and ruamel.yaml сan't parse example 2.23, 2.24, 2.27, 2.28, etc. from YAML spec and also do not pass all tests from yaml-test-suite.

strictyaml use ruamel.yaml as parser so all the bugs are repeated too.

import yaml as pyyaml

example_2_23 = """\
---
not-date: !!str 2002-04-28

picture: !!binary |
 R0lGODlhDAAMAIQAAP//9/X
 17unp5WZmZgAAAOfn515eXv
 Pz7Y6OjuDg4J+fn5OTk6enp
 56enmleECcgggoBADs=

application specific tag: !something |
 The semantics of the tag
 above may be different for
 different documents.
"""
print(pyyaml.safe_load(example_2_23))  # yaml.constructor.ConstructorError
import yaml as pyyaml
from ruamel.yaml import YAML

yaml_safe = YAML(typ="safe")

yaml = "! 15"  # must be str

pyyaml_load = pyyaml.safe_load(yaml)
ruamel_yaml_load = yaml_safe.load(yaml)
print(pyyaml_load)  # 15
print(type(pyyaml_load))  # <class 'int'>
print(ruamel_yaml_load)  # 15
print(type(ruamel_yaml_load))  # <class 'int'>

About

A High-Performance YAML v1.2 Parser for Python written in Rust🦀

Resources

License

Stars

Watchers

Forks

Packages

No packages published