toml-rs 0.0.13__cp310-cp310-win_amd64.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.

Potentially problematic release.


This version of toml-rs might be problematic. Click here for more details.

toml_rs/__init__.py ADDED
@@ -0,0 +1,74 @@
1
+ __all__ = (
2
+ "TOMLDecodeError",
3
+ "TOMLEncodeError",
4
+ "__version__",
5
+ "dump",
6
+ "dumps",
7
+ "load",
8
+ "loads",
9
+ )
10
+
11
+ from collections.abc import Callable
12
+ from pathlib import Path
13
+ from typing import Any, BinaryIO, TextIO
14
+
15
+ from ._toml_rs import (
16
+ _dumps,
17
+ _loads,
18
+ _version,
19
+ )
20
+
21
+ __version__: str = _version
22
+
23
+
24
+ def load(fp: BinaryIO, /, *, parse_float: Callable[[str], Any] = float) -> dict[str, Any]:
25
+ _bytes = fp.read()
26
+ try:
27
+ _str = _bytes.decode()
28
+ except AttributeError:
29
+ msg = "File must be opened in binary mode, e.g. use `open('foo.toml', 'rb')`"
30
+ raise TypeError(msg) from None
31
+ return loads(_str, parse_float=parse_float)
32
+
33
+
34
+ def loads(s: str, /, *, parse_float: Callable[[str], Any] = float) -> dict[str, Any]:
35
+ if not isinstance(s, str):
36
+ raise TypeError(f"Expected str object, not '{type(s).__name__}'")
37
+ return _loads(s, parse_float=parse_float)
38
+
39
+
40
+ def dump(obj: Any, /, file: str | Path | TextIO, *, pretty: bool = False) -> int:
41
+ s = _dumps(obj, pretty=pretty)
42
+ if isinstance(file, str):
43
+ file = Path(file)
44
+ if isinstance(file, Path):
45
+ return file.write_text(s, encoding="utf-8")
46
+ else:
47
+ return file.write(s)
48
+
49
+
50
+ def dumps(obj: Any, /, *, pretty: bool = False) -> str:
51
+ return _dumps(obj, pretty=pretty)
52
+
53
+
54
+ class TOMLDecodeError(ValueError):
55
+ def __init__(self, msg: str, doc: str, pos: int, *args: Any):
56
+ msg = msg.rstrip()
57
+ super().__init__(msg)
58
+ lineno = doc.count("\n", 0, pos) + 1
59
+ if lineno == 1:
60
+ colno = pos + 1
61
+ else:
62
+ colno = pos - doc.rindex("\n", 0, pos)
63
+ self.msg = msg
64
+ self.doc = doc
65
+ self.pos = pos
66
+ self.colno = colno
67
+ self.lineno = lineno
68
+
69
+
70
+ class TOMLEncodeError(TypeError):
71
+ def __init__(self, msg: str, *args: Any):
72
+ msg = msg.rstrip()
73
+ super().__init__(msg)
74
+ self.msg = msg
Binary file
toml_rs/py.typed ADDED
File without changes
@@ -0,0 +1,158 @@
1
+ Metadata-Version: 2.4
2
+ Name: toml-rs
3
+ Version: 0.0.13
4
+ Classifier: Typing :: Typed
5
+ Classifier: Programming Language :: Rust
6
+ Classifier: Programming Language :: Python
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3.10
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Classifier: Programming Language :: Python :: 3.14
13
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
14
+ Classifier: Programming Language :: Python :: Implementation :: CPython
15
+ Classifier: Topic :: Software Development :: Libraries
16
+ Classifier: License :: OSI Approved :: The Unlicense (Unlicense)
17
+ License-File: UNLICENSE
18
+ Summary: A High-Performance TOML Parser for Python written in Rust
19
+ Author-email: chirizxc <chirizxc@proton.me>
20
+ Maintainer-email: chirizxc <chirizxc@proton.me>
21
+ License-Expression: UNLICENSE
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
24
+ Project-URL: Source, https://github.com/lava-sh/toml-rs
25
+ Project-URL: Homepage, https://github.com/lava-sh/toml-rs
26
+ Project-URL: Bug Tracker, https://github.com/lava-sh/toml-rs/issues
27
+
28
+ # toml-rs — A High-Performance TOML Parser for Python written in Rust
29
+
30
+ ## Features
31
+
32
+ * The fastest TOML parser in Python (see [benchmarks](https://github.com/lava-sh/toml-rs/tree/main/benchmark))
33
+
34
+ * Drop-in compatibility with most [`tomllib`](https://docs.python.org/3/library/tomllib.html) use cases (see [below](#differences-with-tomllib))
35
+
36
+ ## Installation
37
+ ```bash
38
+ # Using pip
39
+ pip install toml-rs
40
+
41
+ # Using uv
42
+ uv pip install toml-rs
43
+ ```
44
+
45
+ ## Examples
46
+ ```python
47
+ import tomllib
48
+ from pprint import pprint
49
+
50
+ import toml_rs
51
+
52
+ toml = """\
53
+ title = "TOML Example"
54
+
55
+ [owner]
56
+ name = "Tom Preston-Werner"
57
+ dob = 1979-05-27T07:32:00-08:00
58
+
59
+ [database]
60
+ enabled = true
61
+ ports = [ 8000, 8001, 8002 ]
62
+ data = [ ["delta", "phi"], [3.14] ]
63
+ temp_targets = { cpu = 79.5, case = 72.0 }
64
+
65
+ [servers]
66
+ [servers.alpha]
67
+ ip = "10.0.0.1"
68
+ role = "frontend"
69
+ [servers.beta]
70
+ ip = "10.0.0.2"
71
+ role = "backend"
72
+ """
73
+
74
+ tomllib_loads = tomllib.loads(toml)
75
+ toml_rs_loads = toml_rs.loads(toml)
76
+ toml_rs_dumps = toml_rs.dumps(toml_rs_loads)
77
+
78
+ assert tomllib_loads == toml_rs_loads
79
+
80
+ print("toml_rs.loads:")
81
+ pprint(toml_rs_loads)
82
+ print("toml_rs.dumps:")
83
+ print(toml_rs_dumps)
84
+ ```
85
+
86
+ ## Differences with [`tomllib`](https://docs.python.org/3/library/tomllib.html)
87
+
88
+ 1. More understandable errors
89
+
90
+ ```python
91
+ import tomllib
92
+
93
+ t = """\
94
+ x = 1
95
+ y = 2
96
+ v =
97
+ """
98
+ print(tomllib.loads(t))
99
+ # tomllib.TOMLDecodeError: Invalid value (at line 3, column 5)
100
+ ```
101
+ ```python
102
+ import toml_rs
103
+
104
+ t = """\
105
+ x = 1
106
+ y = 2
107
+ v =
108
+ """
109
+ print(toml_rs.loads(t))
110
+ # toml_rs.TOMLDecodeError: TOML parse error at line 3, column 5
111
+ # |
112
+ # 3 | v =
113
+ # | ^
114
+ # string values must be quoted, expected literal string
115
+ ```
116
+
117
+ 2. Strict compliance with TOML v1.0.0
118
+
119
+ From [TOML spec](https://toml.io/en/v1.0.0#integer):
120
+
121
+ > Arbitrary 64-bit signed integers (from `−2^63` to `2^63−1`) should be accepted and handled losslessly. If an integer cannot be represented losslessly, an error must be thrown.
122
+
123
+ ```python
124
+ import tomllib
125
+
126
+ t = "x = 999_999_999_999_999_999_999_999"
127
+ print(tomllib.loads(t))
128
+ # {'x': 999999999999999999999999} <== speс violation
129
+ ```
130
+ ```python
131
+ import toml_rs
132
+
133
+ t = "x = 999_999_999_999_999_999_999_999"
134
+ print(toml_rs.loads(t))
135
+ # toml_rs.TOMLDecodeError: TOML parse error at line 1, column 5
136
+ # |
137
+ # 1 | x = 999_999_999_999_999_999_999_999
138
+ # | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
139
+ # invalid type: integer `999999999999999999999999` as i128, expected any valid TOML value
140
+ ```
141
+
142
+ 3. Supports serialization (`toml_rs.dumps` and `toml_rs.dump`)
143
+
144
+ ```python
145
+ from pathlib import Path
146
+
147
+ import toml_rs
148
+
149
+ data = {
150
+ "title": "TOML Example",
151
+ "owner": {"name": "Alice", "age": 30},
152
+ }
153
+
154
+ print(toml_rs.dumps(data))
155
+
156
+ toml_rs.dump(data, Path("example.toml"))
157
+ # or `toml_rs.dump(data, "example.toml")`
158
+ ```
@@ -0,0 +1,7 @@
1
+ toml_rs-0.0.13.dist-info/METADATA,sha256=8z59j2YAyvRB7wuPkN8Z3dXRYmoS-xp9MApbcqm_Imk,4049
2
+ toml_rs-0.0.13.dist-info/WHEEL,sha256=EzedEmBOXE1tNSzXszfrmtdogTWmygt86emP3GfIvPc,96
3
+ toml_rs-0.0.13.dist-info/licenses/UNLICENSE,sha256=pO9SJPWzhoS7yVUh8EuWMlwkAsA9o-yzXiMtgqmWKC8,1233
4
+ toml_rs/__init__.py,sha256=QWnz3ay-gZAPI_mnxsiOzcIiG2uMKt_zfTGS_24H050,1998
5
+ toml_rs/_toml_rs.cp310-win_amd64.pyd,sha256=5lSEy5H3ncr5tL2eMzCbiuSrEqNiRwtnlUyCf8UEFlA,595456
6
+ toml_rs/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ toml_rs-0.0.13.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.9.6)
3
+ Root-Is-Purelib: false
4
+ Tag: cp310-cp310-win_amd64
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org/>