MCPcopy Index your code
hub / github.com/emmatyping/ryaml

github.com/emmatyping/ryaml @v0.5.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.5.1 ↗ · + Follow
48 symbols 80 edges 10 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ryaml

Quickly and safely parse yaml

What is ryaml?

ryaml is a Python library that wraps a Rust yaml parser, serde-yaml, to quickly and safely parse and dump yaml to and from Python objects.

It is not fully compatible with PyYAML, and it has a similar design to the json module. The hope is this will be used as a safe and fast yaml parser in lieu of PyYAML.

Like PyYAML, this library implements the YAML 1.1 specification.

Installation

We ship binary wheels for Windows, Linux, and macOS, so as long as you are using Python 3.10+, you can run:

$ python -m pip install ryaml

Otherwise, you will need to build from source. To do so, first install Rust 1.41 stable.

Then you should be able to just

$ git clone https://github.com/emmatyping/ryaml
$ cd ryaml
$ python -m pip install .

Or if you want to build a wheel:

$ git clone https://github.com/emmatyping/ryaml
$ cd ryaml
$ python -m pip install maturin
$ maturin build --release --no-sdist
# OR if you want an abi3 wheel (compatible with Python 3.10+)
$ maturin build --release --no-sdist --cargo-extra-args="--features=abi3"

And a wheel will be created in target/wheels which you can install.

Usage

The API of ryaml is very similar to that of json in the standard library:

You can use ryaml.loads to read from a str:

import ryaml
obj = ryaml.loads('key: [10, "hi"]')
assert isinstance(obj, dict) # True
assert obj['key'][1] == "hi" # True

And ryaml.dumps to dump an object into a yaml file:

import ryaml
s = ryaml.dumps({ 'key' : None })
print(s)
# prints:
# ---
# key: ~

There are also ryaml.load and ryaml.load_all to read yaml document(s) from files:

import ryaml
obj = {'a': [{'b': 1}]}
with open('test.yaml', 'w') as w:
    ryaml.dump(w, obj)
with open('test.yaml', 'r') as r:
    assert ryaml.load(r) == obj
with open('multidoc.yaml', 'w') as multi:
    multi.write('''
---
a:
  key:
...
---
b:
  key:
    ''')
with open('multidoc.yaml', 'r') as multi:
    docs = ryaml.load_all(multi)
assert len(docs) == 2
assert docs[0]['a']['key'] is None

ryaml.load_all will, as seen above, load multiple documents from a single file.

Thanks

This project is standing on the shoulders of giants, and would not be possible without:

pyo3

serde-yaml

yaml-rust

pythonize

Core symbols most depended-on inside this repo

_read_file
called by 2
py-src/ryaml/__init__.py
yaml_to_pyobject
called by 2
src/lib.rs
deserialize_yaml
called by 1
src/lib.rs
deserialize_all_yaml
called by 1
src/lib.rs
serialize_yaml
called by 1
src/lib.rs
pyobject_to_yaml
called by 1
src/lib.rs
loads
called by 1
src/lib.rs
loads_all
called by 1
src/lib.rs

Shape

Function 48

Languages

Python83%
Rust17%

Modules by API surface

tests/test_benchmark.py16 symbols
src/lib.rs8 symbols
tests/test_load.py5 symbols
tests/test_loads.py4 symbols
tests/test_dumps.py4 symbols
tests/test_dump.py4 symbols
py-src/ryaml/__init__.py4 symbols
tests/test_load_all.py2 symbols
tests/conftest.py1 symbols

For agents

$ claude mcp add ryaml \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact