RapidYAML

0.11.1 · active · verified Thu Apr 16

RapidYAML (ryml) is a Python wrapper for a fast C++ library designed to parse and emit YAML. It focuses on performance by exposing a low-level, index-based C++ API that operates with node indices and string views, rather than automatically building Python dict/list structures. The current version is 0.11.1, and it maintains an active release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates parsing a YAML byte string and traversing the resulting tree using RapidYAML's low-level, index-based API. It shows how to find child nodes by key and iterate through sequence items, decoding byte strings to Python strings for output.

import ryml

yaml_bytes = b"""
foo: bar
list:
  - item1
  - item2
"""

tree = ryml.parse(yaml_bytes)

root_id = tree.root_id()
print(f"Root ID: {root_id}")

# Accessing 'foo: bar'
foo_id = tree.find_child(root_id, b"foo")
if foo_id != ryml.NONE:
    print(f"Key: {tree.key(foo_id).decode()}, Value: {tree.val(foo_id).decode()}")

# Accessing 'list'
list_id = tree.find_child(root_id, b"list")
if list_id != ryml.NONE and tree.is_seq(list_id):
    print(f"List items:")
    child_id = tree.first_child(list_id)
    while child_id != ryml.NONE:
        print(f"  - {tree.val(child_id).decode()}")
        child_id = tree.next_sibling(child_id)

view raw JSON →