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:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for ryaml-0.4.0-pp37-pypy37_pp73-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3daac0f0d49b32ebe1443db2c30debf33eeeac8d67309ee57f56f6f80c2f5fa4 |
|
MD5 | 0e07ca0d0252076e309aac1b5caafdcb |
|
BLAKE2b-256 | 4d75b84f67d9c5cc901d27bfac10fe776363679674f21d560f7c163dcf7f86bd |
Hashes for ryaml-0.4.0-pp37-pypy37_pp73-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08a0e29e931cec3423f722e595e7230931bc33d0921d15ad0815f431a7a78fdf |
|
MD5 | 3369a222edce790ebcfa79e02efca618 |
|
BLAKE2b-256 | 886485d9a49cd0a63e8811a30d9da3550504a5671c6146f548a83c0aa3955bdb |
Hashes for ryaml-0.4.0-pp37-pypy37_pp73-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0912998186dd54f251244456b1318b183d44811255de3e12fff7fbbf7caa62b |
|
MD5 | b5a34f2ec3bd250a92cf9e55992b72f6 |
|
BLAKE2b-256 | c0795b0e7845125e6722e5cff1997b6fea316a925dd2e70ca2c22b26a19f644d |
Hashes for ryaml-0.4.0-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3af7f9c8987acd72644487f8810e9b219e000e209ecdc10cfa3583567aaa45bd |
|
MD5 | ca14afb5472da242039bcbf413e4432a |
|
BLAKE2b-256 | b1e361a059b05bb0a242fb76f3293f3c11c8803ca11bb3353c9a8a5fcd2faea3 |
Hashes for ryaml-0.4.0-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4afb9f4484fca689c76a2debd4235fb9c983298b34405733b21b5da67b783b5d |
|
MD5 | 664211e41e5c0a4e532fdf8883a69cbd |
|
BLAKE2b-256 | 4390eac5fd341b14250bcafa1296d1e95eaa06738f16374d62c1c3590fab1073 |
Hashes for ryaml-0.4.0-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16ec8cc378ce86275eff433153e1ed5fc12822d36619b167834e1472f9a3ab19 |
|
MD5 | 4fd94fd64df55c1660d8ef6f2ba63680 |
|
BLAKE2b-256 | 5933145b12fcaba6ece9d6f13ea010caa558a50721df135bc550ac6734c1ca47 |
Hashes for ryaml-0.4.0-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25b33a39d2afe4fb02d05f31567d87590737fcabec331ff8fb7884114103caa2 |
|
MD5 | c1bcdfaad18fda7135adec948b9e7f06 |
|
BLAKE2b-256 | b27b8c1baf5d1ff0fd08802549f19fd94ac0e9b2a39da866cef9e3981bd86f0c |
Hashes for ryaml-0.4.0-cp38-cp38-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34d8587fd87ed07d188c3fa55b6394e0fe9bd86674be8ac4f2aae48efd8e69fe |
|
MD5 | 70f580460de75bd22e04a9d3695cd70e |
|
BLAKE2b-256 | 483e94b7aac7692eec62f1de1984756bbf3bf49828a56838eb05b76d0878f1f5 |
Hashes for ryaml-0.4.0-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 945c9b12ca478824237673715dd5673b82be989ba0aeaee449a9993cf1bd5d76 |
|
MD5 | 5d9c2221760817cf2ffa9ab333fa4476 |
|
BLAKE2b-256 | 6b8e6297925ff453b67d5013d3c4143792c7f67c96ca7827ea4d833f28a4ec92 |
Hashes for ryaml-0.4.0-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0011f6f336852019333346689899810308d70cf6a983e62fc677950ce2f7fafc |
|
MD5 | 47777a67341f13c79ae391f60d9ab57a |
|
BLAKE2b-256 | d771cb00c181d90061379bf2948251def3905043b8571fc2df8c28ed0a49b131 |
Hashes for ryaml-0.4.0-cp37-abi3-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4e4d3cc4380d411d29f3efe2eca888d4fc2df735d7ebfa27fbdc65cf482f803 |
|
MD5 | b87be7138222727ae03ef6de202b5d96 |
|
BLAKE2b-256 | 4559fb2c8bc6a46f9b44dcb618a6f95e77685250e23f2cf1d29d67ed5c20cff8 |
Hashes for ryaml-0.4.0-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d93b76b605d6163abe1fd685196bebfe4c319915249154e22792f1f7d4946b5f |
|
MD5 | c49d5d7f812db937686208ecc05750b4 |
|
BLAKE2b-256 | 25112f55ee4a1e55ed5e6fdce0a7a221d601a8e4076d3ffbfa348bf0444d4745 |
Hashes for ryaml-0.4.0-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67e676764110249ee0b2a021fb95ef29f7c5be5870ad71ae20d73574f94f909a |
|
MD5 | 1b2346a19c6ef24032f8484a10bc2c3b |
|
BLAKE2b-256 | a366e965c1ed625cdb650ba2c21f973f42487dba9e29715c8498f118d5a779f1 |