ryaml 0.5.1__cp313-cp313-manylinux_2_28_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ryaml/__init__.py +34 -0
- ryaml/_ryaml.cpython-313-aarch64-linux-gnu.so +0 -0
- ryaml/_ryaml.pyi +8 -0
- ryaml/py.typed +0 -0
- ryaml-0.5.1.dist-info/METADATA +135 -0
- ryaml-0.5.1.dist-info/RECORD +8 -0
- ryaml-0.5.1.dist-info/WHEEL +5 -0
- ryaml-0.5.1.dist-info/licenses/LICENSE +7 -0
ryaml/__init__.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from ._ryaml import InvalidYamlError, loads, loads_all, dumps
|
|
2
|
+
|
|
3
|
+
from typing import IO, AnyStr, Any
|
|
4
|
+
import io
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _read_file(fp: IO[AnyStr]) -> str:
|
|
8
|
+
data = fp.read()
|
|
9
|
+
if isinstance(data, str):
|
|
10
|
+
return data
|
|
11
|
+
elif isinstance(data, bytes):
|
|
12
|
+
return data.decode("utf8")
|
|
13
|
+
else:
|
|
14
|
+
return bytes(data).decode('utf8')
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def load(fp: IO[AnyStr]) -> Any:
|
|
18
|
+
if not isinstance(fp, io.IOBase):
|
|
19
|
+
raise TypeError("fp must be a file-like object")
|
|
20
|
+
return loads(_read_file(fp))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def load_all(fp: IO[AnyStr]) -> list[Any]:
|
|
24
|
+
if not isinstance(fp, io.IOBase):
|
|
25
|
+
raise TypeError("fp must be a file-like object")
|
|
26
|
+
return loads_all(_read_file(fp))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def dump(fp: IO[AnyStr], obj: Any) -> None:
|
|
30
|
+
yaml = dumps(obj)
|
|
31
|
+
if isinstance(fp, io.TextIOBase):
|
|
32
|
+
fp.write(yaml) # type: ignore
|
|
33
|
+
else:
|
|
34
|
+
fp.write(yaml.encode('utf8')) # type: ignore
|
|
Binary file
|
ryaml/_ryaml.pyi
ADDED
ryaml/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ryaml
|
|
3
|
+
Version: 0.5.1
|
|
4
|
+
Classifier: Programming Language :: Python
|
|
5
|
+
Classifier: Programming Language :: Rust
|
|
6
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
7
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
13
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
14
|
+
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Typing :: Typed
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Summary: A simple yaml serializer and deserializer using Rust.
|
|
18
|
+
Keywords: yaml,parsing
|
|
19
|
+
Author-email: Emma Harper Smith <emma@emmatyping.dev>
|
|
20
|
+
License: MIT
|
|
21
|
+
Requires-Python: >=3.10, <4
|
|
22
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
23
|
+
Project-URL: homepage, https://github.com/emmatyping/ryaml
|
|
24
|
+
Project-URL: repository, https://github.com/emmatyping/ryaml
|
|
25
|
+
|
|
26
|
+
ryaml
|
|
27
|
+
=====
|
|
28
|
+
|
|
29
|
+
### *Quickly and safely parse yaml*
|
|
30
|
+
|
|
31
|
+
### What is ryaml?
|
|
32
|
+
|
|
33
|
+
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.
|
|
34
|
+
|
|
35
|
+
It is *not* fully compatible with PyYAML, and it has a similar design to the `json` module.
|
|
36
|
+
The hope is this will be used as a safe and fast yaml parser in lieu of PyYAML.
|
|
37
|
+
|
|
38
|
+
Like PyYAML, this library implements the YAML 1.1 specification.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
We ship binary wheels for Windows, Linux, and macOS, so as long as you are using Python 3.10+,
|
|
43
|
+
you can run:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
$ python -m pip install ryaml
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Otherwise, you will need to build from source. To do so, first install Rust 1.41 stable.
|
|
50
|
+
|
|
51
|
+
Then you should be able to just
|
|
52
|
+
|
|
53
|
+
```shell
|
|
54
|
+
$ git clone https://github.com/emmatyping/ryaml
|
|
55
|
+
$ cd ryaml
|
|
56
|
+
$ python -m pip install .
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Or if you want to build a wheel:
|
|
60
|
+
|
|
61
|
+
```shell
|
|
62
|
+
$ git clone https://github.com/emmatyping/ryaml
|
|
63
|
+
$ cd ryaml
|
|
64
|
+
$ python -m pip install maturin
|
|
65
|
+
$ maturin build --release --no-sdist
|
|
66
|
+
# OR if you want an abi3 wheel (compatible with Python 3.10+)
|
|
67
|
+
$ maturin build --release --no-sdist --cargo-extra-args="--features=abi3"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
And a wheel will be created in `target/wheels` which you can install.
|
|
71
|
+
|
|
72
|
+
## Usage
|
|
73
|
+
|
|
74
|
+
The API of `ryaml` is very similar to that of `json` in the standard library:
|
|
75
|
+
|
|
76
|
+
You can use `ryaml.loads` to read from a `str`:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import ryaml
|
|
80
|
+
obj = ryaml.loads('key: [10, "hi"]')
|
|
81
|
+
assert isinstance(obj, dict) # True
|
|
82
|
+
assert obj['key'][1] == "hi" # True
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
And `ryaml.dumps` to dump an object into a yaml file:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
import ryaml
|
|
89
|
+
s = ryaml.dumps({ 'key' : None })
|
|
90
|
+
print(s)
|
|
91
|
+
# prints:
|
|
92
|
+
# ---
|
|
93
|
+
# key: ~
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
There are also `ryaml.load` and `ryaml.load_all` to read yaml document(s) from files:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
import ryaml
|
|
100
|
+
obj = {'a': [{'b': 1}]}
|
|
101
|
+
with open('test.yaml', 'w') as w:
|
|
102
|
+
ryaml.dump(w, obj)
|
|
103
|
+
with open('test.yaml', 'r') as r:
|
|
104
|
+
assert ryaml.load(r) == obj
|
|
105
|
+
with open('multidoc.yaml', 'w') as multi:
|
|
106
|
+
multi.write('''
|
|
107
|
+
---
|
|
108
|
+
a:
|
|
109
|
+
key:
|
|
110
|
+
...
|
|
111
|
+
---
|
|
112
|
+
b:
|
|
113
|
+
key:
|
|
114
|
+
''')
|
|
115
|
+
with open('multidoc.yaml', 'r') as multi:
|
|
116
|
+
docs = ryaml.load_all(multi)
|
|
117
|
+
assert len(docs) == 2
|
|
118
|
+
assert docs[0]['a']['key'] is None
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`ryaml.load_all` will, as seen above, load multiple documents from a single file.
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
## Thanks
|
|
125
|
+
|
|
126
|
+
This project is standing on the shoulders of giants, and would not be possible without:
|
|
127
|
+
|
|
128
|
+
[pyo3](https://pyo3.rs/)
|
|
129
|
+
|
|
130
|
+
[serde-yaml](https://github.com/dtolnay/serde-yaml)
|
|
131
|
+
|
|
132
|
+
[yaml-rust](https://github.com/chyh1990/yaml-rust)
|
|
133
|
+
|
|
134
|
+
[pythonize](https://github.com/davidhewitt/pythonize)
|
|
135
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
ryaml/__init__.py,sha256=VBMKz36GaU0A5oho4pUU9AoboTSu3u2LAt5ykk8q8O8,888
|
|
2
|
+
ryaml/_ryaml.cpython-313-aarch64-linux-gnu.so,sha256=jhbTRmfJ5T3zICfM261P3CNLBA5VUP9BLqCXqqrIlXI,1059784
|
|
3
|
+
ryaml/_ryaml.pyi,sha256=YS7vLu742Y96hNo9bHGyvXp4Hil9DAtR_is6v47DOUE,185
|
|
4
|
+
ryaml/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
ryaml-0.5.1.dist-info/METADATA,sha256=SRZKTK91rzR261tGyfQMwok4Fy6GhB-nZk5fZjl6Zwk,3543
|
|
6
|
+
ryaml-0.5.1.dist-info/WHEEL,sha256=HPnTIJNZB_Pw0JlHf7P-2tce6qzRT9c6G3EDMAtT7jg,111
|
|
7
|
+
ryaml-0.5.1.dist-info/RECORD,,
|
|
8
|
+
ryaml-0.5.1.dist-info/licenses/LICENSE,sha256=52M823F7Jiop4_cMBCNgKDnFRK2oTnahO_3vGYAzX3Y,1051
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2021 Ethan Smith
|
|
2
|
+
|
|
3
|
+
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:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
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.
|