Skip to main content

A simple yaml serializer and deserializer using Rust.

Project description

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 compatible with PyYAML, but 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.

Installation

We ship binary wheels for Windows, Linux, and macOS, so as long as you are using Python 3.7+, 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/ethanhs/ryaml
$ cd ryaml
$ python -m pip install .

Or if you want to build a wheel:

$ git clone https://github.com/ethanhs/ryaml
$ cd ryaml
$ python -m pip install maturin
$ maturin build --release --no-sdist
# OR if you want an abi3 wheel (compatible with Python 3.7+)
$ 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

pyo3-file

pythonize

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

ryaml-0.4.0-pp37-pypy37_pp73-manylinux_2_24_x86_64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.24+ x86-64

ryaml-0.4.0-pp37-pypy37_pp73-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (704.3 kB view hashes)

Uploaded PyPy macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

ryaml-0.4.0-pp37-pypy37_pp73-macosx_10_7_x86_64.whl (360.1 kB view hashes)

Uploaded PyPy macOS 10.7+ x86-64

ryaml-0.4.0-cp310-none-win_amd64.whl (241.8 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

ryaml-0.4.0-cp39-none-win_amd64.whl (242.1 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

ryaml-0.4.0-cp39-cp39-macosx_10_7_x86_64.whl (361.9 kB view hashes)

Uploaded CPython 3.9 macOS 10.7+ x86-64

ryaml-0.4.0-cp38-none-win_amd64.whl (242.0 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

ryaml-0.4.0-cp38-cp38-manylinux_2_24_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.24+ x86-64

ryaml-0.4.0-cp37-none-win_amd64.whl (242.1 kB view hashes)

Uploaded CPython 3.7 Windows x86-64

ryaml-0.4.0-cp37-abi3-win_amd64.whl (241.8 kB view hashes)

Uploaded CPython 3.7+ Windows x86-64

ryaml-0.4.0-cp37-abi3-manylinux_2_24_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.24+ x86-64

ryaml-0.4.0-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (710.0 kB view hashes)

Uploaded CPython 3.7+ macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

ryaml-0.4.0-cp37-abi3-macosx_10_7_x86_64.whl (362.2 kB view hashes)

Uploaded CPython 3.7+ macOS 10.7+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page