ryaml 0.5.1__tar.gz

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.
@@ -0,0 +1,10 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "cargo"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "weekly"
7
+ - package-ecosystem: pip
8
+ directory: "/"
9
+ schedule:
10
+ interval: "weekly"
@@ -0,0 +1,133 @@
1
+ name: Build and upload to PyPI
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ pull_request:
6
+ push:
7
+ branches:
8
+ - main
9
+ release:
10
+ types:
11
+ - published
12
+
13
+ concurrency:
14
+ group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
15
+ cancel-in-progress: true
16
+
17
+
18
+ jobs:
19
+ build_wheels:
20
+ name: Build wheels for ${{ matrix.os }} ${{ matrix.build }}
21
+ runs-on: ${{ matrix.runs-on }}
22
+ strategy:
23
+ fail-fast: false
24
+ matrix:
25
+ include:
26
+ - os: linux-intel
27
+ runs-on: ubuntu-latest
28
+ - os: linux-arm
29
+ runs-on: ubuntu-24.04-arm
30
+ - os: windows-intel
31
+ runs-on: windows-latest
32
+ - os: windows-arm
33
+ runs-on: windows-11-arm
34
+ - os: macos-intel
35
+ runs-on: macos-15-intel
36
+ - os: macos-arm
37
+ runs-on: macos-latest
38
+ # TODO(emmatyping): re-enable mobile targets eventually
39
+ #- os: android-intel
40
+ # runs-on: ubuntu-latest
41
+ # platform: android
42
+ #- os: android-arm
43
+ # # GitHub Actions doesn’t currently support the Android emulator on any ARM
44
+ # # runner. So we build on a non-ARM runner, which will skip the tests.
45
+ # runs-on: ubuntu-latest
46
+ # platform: android
47
+ # archs: arm64_v8a
48
+ #- os: ios
49
+ # runs-on: macos-latest
50
+ # platform: ios
51
+ - os: pyodide
52
+ runs-on: ubuntu-latest
53
+ platform: pyodide
54
+ build: 'cp312-pyodide_wasm32'
55
+ # Update when newer Emscripten is used for pyodide
56
+ # ref https://github.com/rust-lang/rust/issues/137315
57
+ toolchain: nightly-2025-02-17
58
+ targets: wasm32-unknown-emscripten
59
+ components: rust-src
60
+ # TODO(emmatyping): re-enable this eventually, once the linking issue
61
+ # is sorted out. It might be that we need to build Rust std
62
+ #- os: pyodide
63
+ # runs-on: ubuntu-latest
64
+ # platform: pyodide
65
+ # build: 'cp313-pyodide_wasm32'
66
+ # toolchain: nightly
67
+ # targets: wasm32-unknown-emscripten
68
+ # components: rust-src
69
+
70
+ steps:
71
+ - uses: actions/checkout@v5
72
+
73
+ - name: install Rust
74
+ uses: dtolnay/rust-toolchain@master
75
+ with:
76
+ toolchain: ${{ matrix.toolchain || 'stable' }}
77
+ targets: ${{ matrix.targets }}
78
+ components: ${{ matrix.components }}
79
+
80
+ - name: cache rust
81
+ uses: Swatinem/rust-cache@v2
82
+ with:
83
+ key: wheel-build-${{ matrix.toolchain || 'stable' }}-${{ matrix.targets }}
84
+
85
+ - name: Build wheels
86
+ uses: pypa/cibuildwheel@v3.3.0
87
+ env:
88
+ CIBW_PLATFORM: ${{ matrix.platform || 'auto' }}
89
+ CIBW_ARCHS: ${{ matrix.archs || 'auto' }}
90
+ CIBW_TEST_REQUIRES: pytest pytest-benchmark pyyaml
91
+ # On pyodide, bare commands may not work, so use python -m pytest
92
+ CIBW_TEST_COMMAND: python -m pytest {project}/tests
93
+ CIBW_ENVIRONMENT: MACOSX_DEPLOYMENT_TARGET=10.12 ${{ matrix.env }}
94
+ CIBW_SKIP: '*-musllinux_* *-win32'
95
+ CIBW_BUILD: ${{ matrix.build }}
96
+ CIBW_XBUILD_TOOLS: rustc cargo
97
+ CIBW_BUILD_VERBOSITY: '1'
98
+
99
+ - uses: actions/upload-artifact@v4
100
+ with:
101
+ name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
102
+ path: ./wheelhouse/*.whl
103
+
104
+ build_sdist:
105
+ name: Build source distribution
106
+ runs-on: ubuntu-latest
107
+ steps:
108
+ - uses: actions/checkout@v5
109
+
110
+ - name: Build sdist
111
+ run: pipx run build --sdist
112
+
113
+ - uses: actions/upload-artifact@v4
114
+ with:
115
+ name: cibw-sdist
116
+ path: dist/*.tar.gz
117
+
118
+ upload_pypi:
119
+ needs: [build_wheels, build_sdist]
120
+ runs-on: ubuntu-latest
121
+ environment: pypi
122
+ permissions:
123
+ id-token: write
124
+ if: github.event_name == 'release' && github.event.action == 'published'
125
+ steps:
126
+ - uses: actions/download-artifact@v5
127
+ with:
128
+ # unpacks all CIBW artifacts except pyodide into dist/
129
+ pattern: "!cibw-wheels-pyodide-*"
130
+ path: dist
131
+ merge-multiple: true
132
+
133
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,37 @@
1
+ name: pre-commit
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ branches:
9
+ - main
10
+ - dev
11
+
12
+ jobs:
13
+ pre-commit:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - name: checkout
17
+ uses: actions/checkout@v5
18
+ - name: setup python
19
+ uses: actions/setup-python@v5
20
+ with:
21
+ python-version: '3.14'
22
+
23
+ - name: Install stable
24
+ uses: dtolnay/rust-toolchain@stable
25
+ with:
26
+ components: rustfmt, clippy
27
+ - name: cache rust
28
+ uses: Swatinem/rust-cache@v2
29
+ with:
30
+ key: pre-commit-v0
31
+ - name: set PY
32
+ run: echo "name=PY::$(python -c 'import hashlib, sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_ENV
33
+ - uses: actions/cache@v4
34
+ with:
35
+ path: ~/.cache/pre-commit
36
+ key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
37
+ - uses: pre-commit/action@v3.0.1
ryaml-0.5.1/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ /target
2
+ .tox/
3
+ .pytest_cache/
4
+ **/__pycache__/
5
+ .vscode/
@@ -0,0 +1,21 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v4.0.1
4
+ hooks:
5
+ - id: trailing-whitespace
6
+ - id: end-of-file-fixer
7
+ - id: check-merge-conflict
8
+ - id: check-symlinks
9
+ - id: mixed-line-ending
10
+ args: ['--fix=lf']
11
+ - id: check-added-large-files
12
+ args: ['--maxkb=8192']
13
+ - id: fix-byte-order-marker
14
+ - id: check-yaml
15
+ - id: fix-encoding-pragma
16
+ args: ['--remove']
17
+ - repo: https://github.com/doublify/pre-commit-rust
18
+ rev: v1.0
19
+ hooks:
20
+ - id: fmt
21
+ - id: clippy
ryaml-0.5.1/Cargo.lock ADDED
@@ -0,0 +1,268 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "autocfg"
7
+ version = "1.5.0"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
10
+
11
+ [[package]]
12
+ name = "equivalent"
13
+ version = "1.0.2"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
16
+
17
+ [[package]]
18
+ name = "hashbrown"
19
+ version = "0.16.0"
20
+ source = "registry+https://github.com/rust-lang/crates.io-index"
21
+ checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d"
22
+
23
+ [[package]]
24
+ name = "heck"
25
+ version = "0.5.0"
26
+ source = "registry+https://github.com/rust-lang/crates.io-index"
27
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
28
+
29
+ [[package]]
30
+ name = "indexmap"
31
+ version = "2.12.0"
32
+ source = "registry+https://github.com/rust-lang/crates.io-index"
33
+ checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f"
34
+ dependencies = [
35
+ "equivalent",
36
+ "hashbrown",
37
+ ]
38
+
39
+ [[package]]
40
+ name = "indoc"
41
+ version = "2.0.7"
42
+ source = "registry+https://github.com/rust-lang/crates.io-index"
43
+ checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706"
44
+ dependencies = [
45
+ "rustversion",
46
+ ]
47
+
48
+ [[package]]
49
+ name = "itoa"
50
+ version = "1.0.15"
51
+ source = "registry+https://github.com/rust-lang/crates.io-index"
52
+ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
53
+
54
+ [[package]]
55
+ name = "libc"
56
+ version = "0.2.177"
57
+ source = "registry+https://github.com/rust-lang/crates.io-index"
58
+ checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
59
+
60
+ [[package]]
61
+ name = "memoffset"
62
+ version = "0.9.1"
63
+ source = "registry+https://github.com/rust-lang/crates.io-index"
64
+ checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
65
+ dependencies = [
66
+ "autocfg",
67
+ ]
68
+
69
+ [[package]]
70
+ name = "once_cell"
71
+ version = "1.21.3"
72
+ source = "registry+https://github.com/rust-lang/crates.io-index"
73
+ checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
74
+
75
+ [[package]]
76
+ name = "portable-atomic"
77
+ version = "1.11.1"
78
+ source = "registry+https://github.com/rust-lang/crates.io-index"
79
+ checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483"
80
+
81
+ [[package]]
82
+ name = "proc-macro2"
83
+ version = "1.0.103"
84
+ source = "registry+https://github.com/rust-lang/crates.io-index"
85
+ checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
86
+ dependencies = [
87
+ "unicode-ident",
88
+ ]
89
+
90
+ [[package]]
91
+ name = "pyo3"
92
+ version = "0.26.0"
93
+ source = "registry+https://github.com/rust-lang/crates.io-index"
94
+ checksum = "7ba0117f4212101ee6544044dae45abe1083d30ce7b29c4b5cbdfa2354e07383"
95
+ dependencies = [
96
+ "indoc",
97
+ "libc",
98
+ "memoffset",
99
+ "once_cell",
100
+ "portable-atomic",
101
+ "pyo3-build-config",
102
+ "pyo3-ffi",
103
+ "pyo3-macros",
104
+ "unindent",
105
+ ]
106
+
107
+ [[package]]
108
+ name = "pyo3-build-config"
109
+ version = "0.26.0"
110
+ source = "registry+https://github.com/rust-lang/crates.io-index"
111
+ checksum = "4fc6ddaf24947d12a9aa31ac65431fb1b851b8f4365426e182901eabfb87df5f"
112
+ dependencies = [
113
+ "target-lexicon",
114
+ ]
115
+
116
+ [[package]]
117
+ name = "pyo3-ffi"
118
+ version = "0.26.0"
119
+ source = "registry+https://github.com/rust-lang/crates.io-index"
120
+ checksum = "025474d3928738efb38ac36d4744a74a400c901c7596199e20e45d98eb194105"
121
+ dependencies = [
122
+ "libc",
123
+ "pyo3-build-config",
124
+ ]
125
+
126
+ [[package]]
127
+ name = "pyo3-macros"
128
+ version = "0.26.0"
129
+ source = "registry+https://github.com/rust-lang/crates.io-index"
130
+ checksum = "2e64eb489f22fe1c95911b77c44cc41e7c19f3082fc81cce90f657cdc42ffded"
131
+ dependencies = [
132
+ "proc-macro2",
133
+ "pyo3-macros-backend",
134
+ "quote",
135
+ "syn",
136
+ ]
137
+
138
+ [[package]]
139
+ name = "pyo3-macros-backend"
140
+ version = "0.26.0"
141
+ source = "registry+https://github.com/rust-lang/crates.io-index"
142
+ checksum = "100246c0ecf400b475341b8455a9213344569af29a3c841d29270e53102e0fcf"
143
+ dependencies = [
144
+ "heck",
145
+ "proc-macro2",
146
+ "pyo3-build-config",
147
+ "quote",
148
+ "syn",
149
+ ]
150
+
151
+ [[package]]
152
+ name = "pythonize"
153
+ version = "0.26.0"
154
+ source = "registry+https://github.com/rust-lang/crates.io-index"
155
+ checksum = "11e06e4cff9be2bbf2bddf28a486ae619172ea57e79787f856572878c62dcfe2"
156
+ dependencies = [
157
+ "pyo3",
158
+ "serde",
159
+ ]
160
+
161
+ [[package]]
162
+ name = "quote"
163
+ version = "1.0.42"
164
+ source = "registry+https://github.com/rust-lang/crates.io-index"
165
+ checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
166
+ dependencies = [
167
+ "proc-macro2",
168
+ ]
169
+
170
+ [[package]]
171
+ name = "rustversion"
172
+ version = "1.0.22"
173
+ source = "registry+https://github.com/rust-lang/crates.io-index"
174
+ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
175
+
176
+ [[package]]
177
+ name = "ryaml"
178
+ version = "0.5.1"
179
+ dependencies = [
180
+ "pyo3",
181
+ "pythonize",
182
+ "serde",
183
+ "serde_yaml",
184
+ ]
185
+
186
+ [[package]]
187
+ name = "ryu"
188
+ version = "1.0.20"
189
+ source = "registry+https://github.com/rust-lang/crates.io-index"
190
+ checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
191
+
192
+ [[package]]
193
+ name = "serde"
194
+ version = "1.0.228"
195
+ source = "registry+https://github.com/rust-lang/crates.io-index"
196
+ checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
197
+ dependencies = [
198
+ "serde_core",
199
+ "serde_derive",
200
+ ]
201
+
202
+ [[package]]
203
+ name = "serde_core"
204
+ version = "1.0.228"
205
+ source = "registry+https://github.com/rust-lang/crates.io-index"
206
+ checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
207
+ dependencies = [
208
+ "serde_derive",
209
+ ]
210
+
211
+ [[package]]
212
+ name = "serde_derive"
213
+ version = "1.0.228"
214
+ source = "registry+https://github.com/rust-lang/crates.io-index"
215
+ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
216
+ dependencies = [
217
+ "proc-macro2",
218
+ "quote",
219
+ "syn",
220
+ ]
221
+
222
+ [[package]]
223
+ name = "serde_yaml"
224
+ version = "0.9.34+deprecated"
225
+ source = "registry+https://github.com/rust-lang/crates.io-index"
226
+ checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47"
227
+ dependencies = [
228
+ "indexmap",
229
+ "itoa",
230
+ "ryu",
231
+ "serde",
232
+ "unsafe-libyaml",
233
+ ]
234
+
235
+ [[package]]
236
+ name = "syn"
237
+ version = "2.0.110"
238
+ source = "registry+https://github.com/rust-lang/crates.io-index"
239
+ checksum = "a99801b5bd34ede4cf3fc688c5919368fea4e4814a4664359503e6015b280aea"
240
+ dependencies = [
241
+ "proc-macro2",
242
+ "quote",
243
+ "unicode-ident",
244
+ ]
245
+
246
+ [[package]]
247
+ name = "target-lexicon"
248
+ version = "0.13.3"
249
+ source = "registry+https://github.com/rust-lang/crates.io-index"
250
+ checksum = "df7f62577c25e07834649fc3b39fafdc597c0a3527dc1c60129201ccfcbaa50c"
251
+
252
+ [[package]]
253
+ name = "unicode-ident"
254
+ version = "1.0.22"
255
+ source = "registry+https://github.com/rust-lang/crates.io-index"
256
+ checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
257
+
258
+ [[package]]
259
+ name = "unindent"
260
+ version = "0.2.4"
261
+ source = "registry+https://github.com/rust-lang/crates.io-index"
262
+ checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
263
+
264
+ [[package]]
265
+ name = "unsafe-libyaml"
266
+ version = "0.2.11"
267
+ source = "registry+https://github.com/rust-lang/crates.io-index"
268
+ checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
ryaml-0.5.1/Cargo.toml ADDED
@@ -0,0 +1,22 @@
1
+ [package]
2
+ name = "ryaml"
3
+ version = "0.5.1"
4
+ edition = "2024"
5
+ authors = ["Emma Harper Smith <emma@emmatyping.dev"]
6
+ readme = "README.md"
7
+
8
+ [lib]
9
+ name = "ryaml"
10
+ crate-type = ["cdylib", "rlib"]
11
+
12
+ [features]
13
+ abi3 = ["pyo3/abi3-py310"]
14
+
15
+ [dependencies]
16
+ serde_yaml = "0.9.34"
17
+ serde = { version = "1.0.228", features = ["derive"] }
18
+ pythonize = "0.26.0"
19
+
20
+ [dependencies.pyo3]
21
+ version = "0.26.0"
22
+ features = ["extension-module"]
ryaml-0.5.1/LICENSE ADDED
@@ -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.
ryaml-0.5.1/PKG-INFO ADDED
@@ -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
+
ryaml-0.5.1/README.md ADDED
@@ -0,0 +1,109 @@
1
+ ryaml
2
+ =====
3
+
4
+ ### *Quickly and safely parse yaml*
5
+
6
+ ### What is ryaml?
7
+
8
+ 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.
9
+
10
+ It is *not* fully compatible with PyYAML, and it has a similar design to the `json` module.
11
+ The hope is this will be used as a safe and fast yaml parser in lieu of PyYAML.
12
+
13
+ Like PyYAML, this library implements the YAML 1.1 specification.
14
+
15
+ ## Installation
16
+
17
+ We ship binary wheels for Windows, Linux, and macOS, so as long as you are using Python 3.10+,
18
+ you can run:
19
+
20
+ ```
21
+ $ python -m pip install ryaml
22
+ ```
23
+
24
+ Otherwise, you will need to build from source. To do so, first install Rust 1.41 stable.
25
+
26
+ Then you should be able to just
27
+
28
+ ```shell
29
+ $ git clone https://github.com/emmatyping/ryaml
30
+ $ cd ryaml
31
+ $ python -m pip install .
32
+ ```
33
+
34
+ Or if you want to build a wheel:
35
+
36
+ ```shell
37
+ $ git clone https://github.com/emmatyping/ryaml
38
+ $ cd ryaml
39
+ $ python -m pip install maturin
40
+ $ maturin build --release --no-sdist
41
+ # OR if you want an abi3 wheel (compatible with Python 3.10+)
42
+ $ maturin build --release --no-sdist --cargo-extra-args="--features=abi3"
43
+ ```
44
+
45
+ And a wheel will be created in `target/wheels` which you can install.
46
+
47
+ ## Usage
48
+
49
+ The API of `ryaml` is very similar to that of `json` in the standard library:
50
+
51
+ You can use `ryaml.loads` to read from a `str`:
52
+
53
+ ```python
54
+ import ryaml
55
+ obj = ryaml.loads('key: [10, "hi"]')
56
+ assert isinstance(obj, dict) # True
57
+ assert obj['key'][1] == "hi" # True
58
+ ```
59
+
60
+ And `ryaml.dumps` to dump an object into a yaml file:
61
+
62
+ ```python
63
+ import ryaml
64
+ s = ryaml.dumps({ 'key' : None })
65
+ print(s)
66
+ # prints:
67
+ # ---
68
+ # key: ~
69
+ ```
70
+
71
+ There are also `ryaml.load` and `ryaml.load_all` to read yaml document(s) from files:
72
+
73
+ ```python
74
+ import ryaml
75
+ obj = {'a': [{'b': 1}]}
76
+ with open('test.yaml', 'w') as w:
77
+ ryaml.dump(w, obj)
78
+ with open('test.yaml', 'r') as r:
79
+ assert ryaml.load(r) == obj
80
+ with open('multidoc.yaml', 'w') as multi:
81
+ multi.write('''
82
+ ---
83
+ a:
84
+ key:
85
+ ...
86
+ ---
87
+ b:
88
+ key:
89
+ ''')
90
+ with open('multidoc.yaml', 'r') as multi:
91
+ docs = ryaml.load_all(multi)
92
+ assert len(docs) == 2
93
+ assert docs[0]['a']['key'] is None
94
+ ```
95
+
96
+ `ryaml.load_all` will, as seen above, load multiple documents from a single file.
97
+
98
+
99
+ ## Thanks
100
+
101
+ This project is standing on the shoulders of giants, and would not be possible without:
102
+
103
+ [pyo3](https://pyo3.rs/)
104
+
105
+ [serde-yaml](https://github.com/dtolnay/serde-yaml)
106
+
107
+ [yaml-rust](https://github.com/chyh1990/yaml-rust)
108
+
109
+ [pythonize](https://github.com/davidhewitt/pythonize)
@@ -0,0 +1,25 @@
1
+ SRC = """
2
+ ---
3
+ - - college
4
+ - -380608299.3165369
5
+ - closely: 595052867
6
+ born: false
7
+ stomach: true
8
+ expression: true
9
+ chosen: 34749965
10
+ somebody: false
11
+ - positive
12
+ - true
13
+ - false
14
+ - price
15
+ - 2018186817
16
+ - average
17
+ - young
18
+ - -1447308110
19
+
20
+ """
21
+
22
+ import ryaml
23
+
24
+ for _ in range(1000):
25
+ ryaml.loads(SRC)
@@ -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
@@ -0,0 +1,8 @@
1
+ # pyright: strict
2
+ from typing import Any
3
+
4
+ class InvalidYamlError(ValueError): ...
5
+
6
+ def loads(s: str) -> Any: ...
7
+ def loads_all(s: str) -> list[Any]: ...
8
+ def dumps(obj: Any) -> str: ...
File without changes
@@ -0,0 +1,47 @@
1
+ [build-system]
2
+ requires = [
3
+ "maturin>=1,<2",
4
+ "wheel",
5
+ ]
6
+ build-backend = "maturin"
7
+
8
+ [project]
9
+ name = "ryaml"
10
+ version = "0.5.1"
11
+ description = "A simple yaml serializer and deserializer using Rust."
12
+ readme = "README.md"
13
+ requires-python = ">=3.10,<4"
14
+ license = {text = "MIT"}
15
+ keywords = ["yaml", "parsing"]
16
+ authors = [
17
+ { name = "Emma Harper Smith", email = "emma@emmatyping.dev" },
18
+ ]
19
+ classifiers = [
20
+ "Programming Language :: Python",
21
+ "Programming Language :: Rust",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Programming Language :: Python :: 3.13",
26
+ "Programming Language :: Python :: 3.14",
27
+ "Development Status :: 3 - Alpha",
28
+ "Operating System :: Microsoft :: Windows",
29
+ "Operating System :: POSIX :: Linux",
30
+ "Operating System :: MacOS",
31
+ "Typing :: Typed",
32
+ ]
33
+
34
+ [project.urls]
35
+ homepage = "https://github.com/emmatyping/ryaml"
36
+ repository = "https://github.com/emmatyping/ryaml"
37
+
38
+ [tool.maturin]
39
+ python-source = "py-src"
40
+ module-name = "ryaml._ryaml"
41
+ include = [
42
+ { format = "sdist", path = "tox.ini" },
43
+ { format = "sdist", path = "Cargo.lock" },
44
+ { format = "sdist", path = "examples/" },
45
+ ]
46
+
47
+ [tool.cibuildwheel]
ryaml-0.5.1/src/lib.rs ADDED
@@ -0,0 +1,85 @@
1
+ pyo3::create_exception!(_ryaml, InvalidYamlError, pyo3::exceptions::PyValueError);
2
+
3
+ #[pyo3::pymodule(gil_used = false)]
4
+ mod _ryaml {
5
+
6
+ use pyo3::Python;
7
+ use pyo3::types::PyList;
8
+ use pyo3::{exceptions::PyValueError, prelude::*};
9
+
10
+ use pythonize::{depythonize, pythonize};
11
+ use serde::Deserialize;
12
+ use serde_yaml::Value;
13
+
14
+ #[pymodule_export]
15
+ use super::InvalidYamlError;
16
+
17
+ fn deserialize_yaml(str: String) -> PyResult<Value> {
18
+ match serde_yaml::from_str(&str) {
19
+ Ok(val) => Ok(val),
20
+ Err(err) => Err(InvalidYamlError::new_err(err.to_string())),
21
+ }
22
+ }
23
+
24
+ fn deserialize_all_yaml(str: String) -> PyResult<Vec<Value>> {
25
+ let mut documents = vec![];
26
+ for document in serde_yaml::Deserializer::from_str(&str) {
27
+ match Value::deserialize(document) {
28
+ Ok(value) => documents.push(value),
29
+ Err(e) => return Err(InvalidYamlError::new_err(e.to_string())),
30
+ }
31
+ }
32
+ Ok(documents)
33
+ }
34
+
35
+ fn serialize_yaml(yaml: &Value) -> PyResult<String> {
36
+ match serde_yaml::to_string(&yaml) {
37
+ Ok(s) => Ok(s),
38
+ Err(err) => Err(PyValueError::new_err(err.to_string())),
39
+ }
40
+ }
41
+
42
+ fn yaml_to_pyobject(py: Python, yaml: &Value) -> PyResult<Py<PyAny>> {
43
+ match pythonize(py, yaml) {
44
+ Ok(obj) => Ok(obj.unbind()),
45
+ Err(err) => Err(PyValueError::new_err(err.to_string())),
46
+ }
47
+ }
48
+
49
+ fn pyobject_to_yaml(py: Python, obj: Py<PyAny>) -> PyResult<Value> {
50
+ match depythonize(obj.bind(py)) {
51
+ Ok(obj) => Ok(obj),
52
+ Err(err) => Err(PyValueError::new_err(err.to_string())),
53
+ }
54
+ }
55
+
56
+ #[pyfunction]
57
+ fn loads(py: Python, str: String) -> PyResult<Py<PyAny>> {
58
+ if str.is_empty() {
59
+ Ok(Python::None(py))
60
+ } else {
61
+ let value = deserialize_yaml(str)?;
62
+ yaml_to_pyobject(py, &value)
63
+ }
64
+ }
65
+
66
+ #[pyfunction]
67
+ fn loads_all(py: Python, str: String) -> PyResult<Py<PyAny>> {
68
+ if str.is_empty() {
69
+ Ok(Python::None(py))
70
+ } else {
71
+ let documents = deserialize_all_yaml(str)?;
72
+ let mut pydocs = vec![];
73
+ for doc in documents {
74
+ pydocs.push(yaml_to_pyobject(py, &doc)?);
75
+ }
76
+ Ok(PyList::new(py, pydocs)?.into_any().unbind())
77
+ }
78
+ }
79
+
80
+ #[pyfunction]
81
+ fn dumps(py: Python, obj: Py<PyAny>) -> PyResult<String> {
82
+ let yaml = pyobject_to_yaml(py, obj)?;
83
+ serialize_yaml(&yaml)
84
+ }
85
+ }
@@ -0,0 +1,8 @@
1
+ import pytest
2
+ import io
3
+
4
+ @pytest.fixture
5
+ def yaml_file(tmp_path):
6
+ with open(tmp_path / 'testfile.yaml', 'w+', encoding='utf8') as y:
7
+ assert isinstance(y, io.TextIOBase)
8
+ yield y
@@ -0,0 +1,153 @@
1
+ import ryaml
2
+ import yaml
3
+ import platform
4
+ import pytest
5
+
6
+ if platform.python_implementation() == 'CPython':
7
+ try:
8
+ from yaml import CSafeLoader as Loader, CDumper as Dumper
9
+ except ImportError:
10
+ pytest.skip(allow_module_level=True)
11
+ else:
12
+ from yaml import SafeLoader as Loader, Dumper as Dumper
13
+
14
+ DATA = [['college', -380608299.3165369, {'closely': 595052867, 'born': False, 'stomach': True, 'expression': True,
15
+ 'chosen': 34749965, 'somebody': False}, 'positive', True, False], 'price', 2018186817, 'average', 'young', -1447308110]
16
+
17
+ SRC = """
18
+ ---
19
+ - - college
20
+ - -380608299.3165369
21
+ - closely: 595052867
22
+ born: false
23
+ stomach: true
24
+ expression: true
25
+ chosen: 34749965
26
+ somebody: false
27
+ - positive
28
+ - true
29
+ - false
30
+ - price
31
+ - 2018186817
32
+ - average
33
+ - young
34
+ - -1447308110
35
+
36
+ """
37
+
38
+ MULTIDOC = """
39
+ ---
40
+ basis: true
41
+ discussion: 1690275082
42
+ twice: count
43
+ another: false
44
+ tiny:
45
+ worth: straw
46
+ plus: ride
47
+ duty: basis
48
+ wave:
49
+ - seeing
50
+ - outline
51
+ - true
52
+ - congress
53
+ - -870479755
54
+ - truck
55
+ large: rhyme
56
+ load: did
57
+ ...
58
+ ---
59
+ getting:
60
+ final:
61
+ - false
62
+ - true
63
+ - -2020793880.414512
64
+ - true
65
+ - -950872146.990103
66
+ - thing
67
+ arrange: naturally
68
+ breakfast: 1065730575
69
+ clothes: drop
70
+ mean: flame
71
+ north: silly
72
+ fireplace: why
73
+ prove: true
74
+ various: true
75
+ breeze: true
76
+ us: true
77
+ """
78
+
79
+
80
+ @pytest.mark.benchmark(group="dump")
81
+ def test_ryaml_bench_dump(benchmark, yaml_file):
82
+ benchmark(ryaml.dump, yaml_file, DATA)
83
+
84
+
85
+ @pytest.mark.benchmark(group="dump")
86
+ def test_pyyaml_bench_dump(benchmark, yaml_file):
87
+ benchmark(yaml.dump, DATA, yaml_file, Dumper=Dumper)
88
+
89
+
90
+ @pytest.mark.benchmark(group="dumps")
91
+ def test_ryaml_bench_dumps(benchmark):
92
+ benchmark(ryaml.dumps, DATA)
93
+
94
+
95
+ @pytest.mark.benchmark(group="dumps")
96
+ def test_pyyaml_bench_dumps(benchmark):
97
+ benchmark(yaml.dump, DATA, Dumper=Dumper)
98
+
99
+
100
+ @pytest.mark.benchmark(group="load")
101
+ def test_ryaml_bench_load(benchmark, yaml_file):
102
+ benchmark(ryaml.load, yaml_file)
103
+
104
+
105
+ @pytest.mark.benchmark(group="load")
106
+ def test_pyyaml_bench_load(benchmark, yaml_file):
107
+ benchmark(yaml.load, yaml_file, Loader=Loader)
108
+
109
+
110
+ @pytest.mark.benchmark(group="loads")
111
+ def test_ryaml_bench_loads(benchmark):
112
+ benchmark(ryaml.loads, SRC)
113
+
114
+
115
+ @pytest.mark.benchmark(group="loads")
116
+ def test_pyyaml_bench_loads(benchmark):
117
+ benchmark(yaml.load, SRC, Loader=Loader)
118
+
119
+
120
+ def ryaml_load_all(file):
121
+ ryaml.load_all(file)
122
+
123
+
124
+ def pyyaml_load_all(file):
125
+ list(yaml.load_all(file, Loader=Loader))
126
+
127
+
128
+ @pytest.mark.benchmark(group="load_all")
129
+ def test_ryaml_bench_load_all(benchmark, yaml_file):
130
+ benchmark(ryaml_load_all, yaml_file)
131
+
132
+
133
+ @pytest.mark.benchmark(group="load_all")
134
+ def test_pyyaml_bench_load_all(benchmark, yaml_file):
135
+ benchmark(pyyaml_load_all, yaml_file)
136
+
137
+
138
+ def ryaml_loads_all(str):
139
+ list(ryaml.loads_all(str))
140
+
141
+
142
+ def pyyaml_loads_all(str):
143
+ list(yaml.load_all(str, Loader=Loader))
144
+
145
+
146
+ @pytest.mark.benchmark(group="loads_all")
147
+ def test_ryaml_bench_loads_all(benchmark):
148
+ benchmark(ryaml_loads_all, MULTIDOC)
149
+
150
+
151
+ @pytest.mark.benchmark(group="loads_all")
152
+ def test_pyyaml_bench_loads_all(benchmark):
153
+ benchmark(pyyaml_loads_all, MULTIDOC)
@@ -0,0 +1,21 @@
1
+ import ryaml
2
+
3
+ def test_dump_none(yaml_file):
4
+ ryaml.dump(yaml_file, None)
5
+ yaml_file.seek(0)
6
+ assert yaml_file.read() == "null\n"
7
+
8
+ def test_dump_key(yaml_file):
9
+ ryaml.dump(yaml_file, { 'key': None })
10
+ yaml_file.seek(0)
11
+ assert yaml_file.read() == 'key: null\n'
12
+
13
+ def test_dump_key_value(yaml_file):
14
+ ryaml.dump(yaml_file, { 'key': 4 })
15
+ yaml_file.seek(0)
16
+ assert yaml_file.read() == 'key: 4\n'
17
+
18
+ def test_dump_key_sequence(yaml_file):
19
+ ryaml.dump(yaml_file, { 'key': [4, 5] })
20
+ yaml_file.seek(0)
21
+ assert yaml_file.read() == 'key:\n- 4\n- 5\n'
@@ -0,0 +1,13 @@
1
+ import ryaml
2
+
3
+ def test_dumps_none():
4
+ assert ryaml.dumps(None) == 'null\n'
5
+
6
+ def test_dumps_key():
7
+ assert ryaml.dumps({ 'key': None }) == 'key: null\n'
8
+
9
+ def test_dumps_key_value():
10
+ assert ryaml.dumps({ 'key': 4 }) == 'key: 4\n'
11
+
12
+ def test_dumps_key_sequence():
13
+ assert ryaml.dumps({ 'key': [4, 5] }) == 'key:\n- 4\n- 5\n'
@@ -0,0 +1,35 @@
1
+ import ryaml
2
+
3
+ def test_load_empty(yaml_file):
4
+ yaml_file.write('')
5
+ yaml_file.seek(0)
6
+ ryaml.load(yaml_file) is None
7
+
8
+ def test_load_key(yaml_file):
9
+ yaml_file.write('key:')
10
+ yaml_file.seek(0)
11
+ ryaml.load(yaml_file) == { 'key': None }
12
+
13
+ def test_load_key_value(yaml_file):
14
+ yaml_file.write('''
15
+ key:
16
+ 4
17
+
18
+ ''')
19
+ yaml_file.seek(0)
20
+ ryaml.load(yaml_file) == { 'key': 4 }
21
+
22
+ def test_load_key_sequence(yaml_file):
23
+ yaml_file.write('''
24
+ key:
25
+ - 4
26
+ - 5
27
+
28
+ ''')
29
+ yaml_file.seek(0)
30
+ ryaml.load(yaml_file) == { 'key': [4, 5] }
31
+
32
+ def test_load_non_ascii(yaml_file):
33
+ yaml_file.write('key: 你好')
34
+ yaml_file.seek(0)
35
+ ryaml.load(yaml_file) == { 'key': '你好' }
@@ -0,0 +1,17 @@
1
+ import ryaml
2
+
3
+ def test_load_all_empty(yaml_file):
4
+ yaml_file.write('')
5
+ yaml_file.seek(0)
6
+ ryaml.load_all(yaml_file) is None
7
+
8
+ def test_load_all_keys(yaml_file):
9
+ yaml_file.write('''
10
+ ---
11
+ key:~
12
+ ...
13
+ ---
14
+ key2:~
15
+ ''')
16
+ yaml_file.seek(0)
17
+ ryaml.load(yaml_file) == [{ 'key': None }, { 'key2': None }]
@@ -0,0 +1,25 @@
1
+ import ryaml
2
+
3
+ def test_loads_empty():
4
+ ryaml.loads('') is None
5
+
6
+ def test_loads_key():
7
+ assert ryaml.loads('''
8
+ key:
9
+
10
+ ''') == { 'key': None }
11
+
12
+ def test_loads_key_value():
13
+ assert ryaml.loads('''
14
+ key:
15
+ 4
16
+
17
+ ''') == { 'key': 4 }
18
+
19
+ def test_loads_key_sequence():
20
+ assert ryaml.loads('''
21
+ key:
22
+ - 4
23
+ - 5
24
+
25
+ ''') == { 'key': [4, 5] }
ryaml-0.5.1/tox.ini ADDED
@@ -0,0 +1,31 @@
1
+ [tox]
2
+ isolated_build = True
3
+ minversion = 3.20.0
4
+ envlist =
5
+ lint
6
+ py310
7
+ py311
8
+ py312
9
+ py313
10
+ py314
11
+ pypy3
12
+
13
+ [testenv]
14
+ description = run the test driver with {basepython}
15
+ deps =
16
+ pyyaml
17
+ pytest
18
+ pytest-benchmark
19
+ commands = pytest {posargs}
20
+
21
+ [testenv:lint]
22
+ skip_install = True
23
+ basepython = python3
24
+ deps = pre-commit>=3.4.0
25
+ commands = pre-commit run --all-files --show-diff-on-failure {posargs:}
26
+
27
+ [pytest]
28
+ minversion = 6.0
29
+ python_files = test*.py
30
+ testpaths =
31
+ tests