Metadata-Version: 2.1
Name: ryaml
Version: 0.2.0
Classifier: Programming Language :: Python
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Development Status :: 3 - Alpha
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS
Summary: A simple yaml serializer and deserializer using Rust.
Keywords: 
Author: 
Author-email: Ethan Smith <ethan@ethanhs.me>
Maintainer: 
Maintainer-email: Ethan Smith <ethan@ethanhs.me>
License:  Copyright 2021 Ethan Smith
 
 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 
 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
Requires-Python: >=3.7,<4
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: repository, https://github.com/ethanhs/ryaml
Project-URL: homepage, https://github.com/ethanhs/ryaml

ryaml
=====

### *Quickly and safely parse yaml*

### What is ryaml?

ryaml is a Python library that wraps a Rust yaml parser, [serde-yaml](https://github.com/dtolnay/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

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

Or if you want to build a wheel:

```shell
$ 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`:

```python
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:

```python
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:

```python
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](https://pyo3.rs/)

[serde-yaml](https://github.com/dtolnay/serde-yaml)

[yaml-rust](https://github.com/chyh1990/yaml-rust)

[pyo3-file](https://github.com/omerbenamram/pyo3-file)

[pythonize](https://github.com/davidhewitt/pythonize)

