toml-rs 0.0.6__cp314-cp314t-win_amd64.whl → 0.2.0__cp314-cp314t-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.
- toml_rs/__init__.py +75 -7
- toml_rs/_toml_rs.cp314t-win_amd64.pyd +0 -0
- toml_rs-0.2.0.dist-info/METADATA +179 -0
- toml_rs-0.2.0.dist-info/RECORD +7 -0
- {toml_rs-0.0.6.dist-info → toml_rs-0.2.0.dist-info}/WHEEL +1 -1
- toml_rs-0.0.6.dist-info/METADATA +0 -84
- toml_rs-0.0.6.dist-info/RECORD +0 -7
- {toml_rs-0.0.6.dist-info → toml_rs-0.2.0.dist-info}/licenses/UNLICENSE +0 -0
toml_rs/__init__.py
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
__all__ = (
|
|
2
2
|
"TOMLDecodeError",
|
|
3
|
+
"TOMLEncodeError",
|
|
3
4
|
"__version__",
|
|
5
|
+
"dump",
|
|
6
|
+
"dumps",
|
|
4
7
|
"load",
|
|
5
8
|
"loads",
|
|
6
9
|
)
|
|
7
10
|
|
|
8
11
|
from collections.abc import Callable
|
|
9
|
-
from
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any, BinaryIO, Literal, TextIO
|
|
10
14
|
|
|
11
15
|
from ._toml_rs import (
|
|
12
|
-
|
|
16
|
+
_dumps,
|
|
13
17
|
_loads,
|
|
14
18
|
_version,
|
|
15
19
|
)
|
|
@@ -17,14 +21,71 @@ from ._toml_rs import (
|
|
|
17
21
|
__version__: str = _version
|
|
18
22
|
|
|
19
23
|
|
|
20
|
-
def load(
|
|
21
|
-
|
|
24
|
+
def load(
|
|
25
|
+
fp: BinaryIO,
|
|
26
|
+
/,
|
|
27
|
+
*,
|
|
28
|
+
parse_float: Callable[[str], Any] = float,
|
|
29
|
+
toml_version: Literal["1.0.0", "1.1.0"] = "1.0.0",
|
|
30
|
+
) -> dict[str, Any]:
|
|
31
|
+
_bytes = fp.read()
|
|
32
|
+
try:
|
|
33
|
+
_str = _bytes.decode()
|
|
34
|
+
except AttributeError:
|
|
35
|
+
msg = "File must be opened in binary mode, e.g. use `open('foo.toml', 'rb')`"
|
|
36
|
+
raise TypeError(msg) from None
|
|
37
|
+
return loads(_str, parse_float=parse_float, toml_version=toml_version)
|
|
22
38
|
|
|
23
39
|
|
|
24
|
-
def loads(
|
|
40
|
+
def loads(
|
|
41
|
+
s: str,
|
|
42
|
+
/,
|
|
43
|
+
*,
|
|
44
|
+
parse_float: Callable[[str], Any] = float,
|
|
45
|
+
toml_version: Literal["1.0.0", "1.1.0"] = "1.0.0",
|
|
46
|
+
) -> dict[str, Any]:
|
|
25
47
|
if not isinstance(s, str):
|
|
26
|
-
raise TypeError(f"Expected str object, not '{type(s).
|
|
27
|
-
return _loads(s, parse_float=parse_float)
|
|
48
|
+
raise TypeError(f"Expected str object, not '{type(s).__qualname__}'")
|
|
49
|
+
return _loads(s, parse_float=parse_float, toml_version=toml_version)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def dump(
|
|
53
|
+
obj: Any,
|
|
54
|
+
/,
|
|
55
|
+
file: str | Path | TextIO,
|
|
56
|
+
inline_tables: set[str] | None = None,
|
|
57
|
+
*,
|
|
58
|
+
pretty: bool = False,
|
|
59
|
+
toml_version: Literal["1.0.0", "1.1.0"] = "1.0.0",
|
|
60
|
+
) -> int:
|
|
61
|
+
_str = _dumps(
|
|
62
|
+
obj,
|
|
63
|
+
inline_tables=inline_tables,
|
|
64
|
+
pretty=pretty,
|
|
65
|
+
toml_version=toml_version,
|
|
66
|
+
)
|
|
67
|
+
if isinstance(file, str):
|
|
68
|
+
file = Path(file)
|
|
69
|
+
if isinstance(file, Path):
|
|
70
|
+
return file.write_text(_str, encoding="utf-8")
|
|
71
|
+
else:
|
|
72
|
+
return file.write(_str)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def dumps(
|
|
76
|
+
obj: Any,
|
|
77
|
+
/,
|
|
78
|
+
inline_tables: set[str] | None = None,
|
|
79
|
+
*,
|
|
80
|
+
pretty: bool = False,
|
|
81
|
+
toml_version: Literal["1.0.0", "1.1.0"] = "1.0.0",
|
|
82
|
+
) -> str:
|
|
83
|
+
return _dumps(
|
|
84
|
+
obj,
|
|
85
|
+
inline_tables=inline_tables,
|
|
86
|
+
pretty=pretty,
|
|
87
|
+
toml_version=toml_version,
|
|
88
|
+
)
|
|
28
89
|
|
|
29
90
|
|
|
30
91
|
class TOMLDecodeError(ValueError):
|
|
@@ -41,3 +102,10 @@ class TOMLDecodeError(ValueError):
|
|
|
41
102
|
self.pos = pos
|
|
42
103
|
self.colno = colno
|
|
43
104
|
self.lineno = lineno
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class TOMLEncodeError(TypeError):
|
|
108
|
+
def __init__(self, msg: str, *args: Any):
|
|
109
|
+
msg = msg.rstrip()
|
|
110
|
+
super().__init__(msg)
|
|
111
|
+
self.msg = msg
|
|
Binary file
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: toml-rs
|
|
3
|
+
Version: 0.2.0
|
|
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
|
+
<div align="center">
|
|
29
|
+
|
|
30
|
+
# toml-rs
|
|
31
|
+
|
|
32
|
+
*A High-Performance TOML v1.0.0 and v1.1.0 parser for Python written in Rust*
|
|
33
|
+
|
|
34
|
+
[](https://pypi.org/project/toml_rs/)
|
|
35
|
+
[](https://pypi.org/project/toml_rs/)
|
|
36
|
+
[](https://pypi.org/project/toml_rs/)
|
|
37
|
+
|
|
38
|
+
[](https://pypi.org/project/toml_rs/)
|
|
39
|
+
[](https://github.com/lava-sh/toml-rs)
|
|
40
|
+
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
## Features
|
|
44
|
+
|
|
45
|
+
* The fastest TOML parser in Python (see [benchmarks](https://github.com/lava-sh/toml-rs/tree/main/benchmark))
|
|
46
|
+
|
|
47
|
+
* Drop-in compatibility with most [`tomllib`](https://docs.python.org/3/library/tomllib.html) use cases (see [below](#differences-with-tomllib))
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# Using pip
|
|
53
|
+
pip install toml-rs
|
|
54
|
+
|
|
55
|
+
# Using uv
|
|
56
|
+
uv pip install toml-rs
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Examples
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import tomllib
|
|
63
|
+
from pprint import pprint
|
|
64
|
+
|
|
65
|
+
import toml_rs
|
|
66
|
+
|
|
67
|
+
toml = """\
|
|
68
|
+
title = "TOML Example"
|
|
69
|
+
|
|
70
|
+
[owner]
|
|
71
|
+
name = "Tom Preston-Werner"
|
|
72
|
+
dob = 1979-05-27T07:32:00-08:00
|
|
73
|
+
|
|
74
|
+
[database]
|
|
75
|
+
enabled = true
|
|
76
|
+
ports = [ 8000, 8001, 8002 ]
|
|
77
|
+
data = [ ["delta", "phi"], [3.14] ]
|
|
78
|
+
temp_targets = { cpu = 79.5, case = 72.0 }
|
|
79
|
+
|
|
80
|
+
[servers]
|
|
81
|
+
[servers.alpha]
|
|
82
|
+
ip = "10.0.0.1"
|
|
83
|
+
role = "frontend"
|
|
84
|
+
[servers.beta]
|
|
85
|
+
ip = "10.0.0.2"
|
|
86
|
+
role = "backend"
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
tomllib_loads = tomllib.loads(toml)
|
|
90
|
+
toml_rs_loads = toml_rs.loads(toml)
|
|
91
|
+
toml_rs_dumps = toml_rs.dumps(toml_rs_loads)
|
|
92
|
+
|
|
93
|
+
assert tomllib_loads == toml_rs_loads
|
|
94
|
+
|
|
95
|
+
print("toml_rs.loads:")
|
|
96
|
+
pprint(toml_rs_loads)
|
|
97
|
+
print("toml_rs.dumps:")
|
|
98
|
+
print(toml_rs_dumps)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Differences with [`tomllib`](https://docs.python.org/3/library/tomllib.html)
|
|
102
|
+
|
|
103
|
+
1. More understandable errors
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
import tomllib
|
|
107
|
+
|
|
108
|
+
t = """\
|
|
109
|
+
x = 1
|
|
110
|
+
y = 2
|
|
111
|
+
v =
|
|
112
|
+
"""
|
|
113
|
+
print(tomllib.loads(t))
|
|
114
|
+
# tomllib.TOMLDecodeError: Invalid value (at line 3, column 5)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
import toml_rs
|
|
119
|
+
|
|
120
|
+
t = """\
|
|
121
|
+
x = 1
|
|
122
|
+
y = 2
|
|
123
|
+
v =
|
|
124
|
+
"""
|
|
125
|
+
print(toml_rs.loads(t))
|
|
126
|
+
# toml_rs.TOMLDecodeError: TOML parse error at line 3, column 5
|
|
127
|
+
# |
|
|
128
|
+
# 3 | v =
|
|
129
|
+
# | ^
|
|
130
|
+
# string values must be quoted, expected literal string
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
2. Strict compliance with TOML v1.0.0
|
|
134
|
+
|
|
135
|
+
From [TOML spec](https://toml.io/en/v1.0.0#integer):
|
|
136
|
+
|
|
137
|
+
> 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.
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
import tomllib
|
|
141
|
+
|
|
142
|
+
t = "x = 999_999_999_999_999_999_999_999"
|
|
143
|
+
print(tomllib.loads(t))
|
|
144
|
+
# {'x': 999999999999999999999999} <== speс violation
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
import toml_rs
|
|
149
|
+
|
|
150
|
+
t = "x = 999_999_999_999_999_999_999_999"
|
|
151
|
+
print(toml_rs.loads(t))
|
|
152
|
+
# toml_rs.TOMLDecodeError: TOML parse error at line 1, column 5
|
|
153
|
+
# |
|
|
154
|
+
# 1 | x = 999_999_999_999_999_999_999_999
|
|
155
|
+
# | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
156
|
+
# invalid type: integer `999999999999999999999999` as i128, expected any valid TOML value
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Note: TOML v1.1.0 allows parsers to support integers and floats beyond `i64`/`f64` limits,
|
|
160
|
+
so the behavior will be the same as [`tomllib`](https://docs.python.org/3/library/tomllib.html)
|
|
161
|
+
|
|
162
|
+
3. Supports serialization (`toml_rs.dumps` and `toml_rs.dump`)
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
from pathlib import Path
|
|
166
|
+
|
|
167
|
+
import toml_rs
|
|
168
|
+
|
|
169
|
+
data = {
|
|
170
|
+
"title": "TOML Example",
|
|
171
|
+
"owner": {"name": "Alice", "age": 30},
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
print(toml_rs.dumps(data))
|
|
175
|
+
|
|
176
|
+
toml_rs.dump(data, Path("example.toml"))
|
|
177
|
+
# or `toml_rs.dump(data, "example.toml")`
|
|
178
|
+
```
|
|
179
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
toml_rs-0.2.0.dist-info/METADATA,sha256=P2_ZcVUcRFAdTXCTMACj0qUcwofqoKhwLjBtA-BzlHE,4928
|
|
2
|
+
toml_rs-0.2.0.dist-info/WHEEL,sha256=kee6LsGytVOkPnxDiMvgzc1PY-2HQL3iJ66h1TyPAyI,98
|
|
3
|
+
toml_rs-0.2.0.dist-info/licenses/UNLICENSE,sha256=pO9SJPWzhoS7yVUh8EuWMlwkAsA9o-yzXiMtgqmWKC8,1233
|
|
4
|
+
toml_rs/__init__.py,sha256=1vith0RH50xfp86FqY_Nrd5idD_9WgieLSBXeu4-mtw,2687
|
|
5
|
+
toml_rs/_toml_rs.cp314t-win_amd64.pyd,sha256=r_M6V1ekPugzdNLR_gWLWjw2h1g9AeK4Nu8zB-GzT2A,894464
|
|
6
|
+
toml_rs/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
toml_rs-0.2.0.dist-info/RECORD,,
|
toml_rs-0.0.6.dist-info/METADATA
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: toml-rs
|
|
3
|
-
Version: 0.0.6
|
|
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
|
|
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
|
-
from pprint import pprint
|
|
48
|
-
|
|
49
|
-
import toml_rs
|
|
50
|
-
import tomllib
|
|
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
|
-
|
|
77
|
-
assert tomllib_loads == toml_rs_loads
|
|
78
|
-
|
|
79
|
-
print("tomllib:")
|
|
80
|
-
pprint(tomllib_loads)
|
|
81
|
-
print("toml_rs:")
|
|
82
|
-
pprint(toml_rs_loads)
|
|
83
|
-
```
|
|
84
|
-
|
toml_rs-0.0.6.dist-info/RECORD
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
toml_rs-0.0.6.dist-info/METADATA,sha256=HbODFJ90NPcc4tEBGJ1ZzK1Wx3Syu7pIKCLuP9k7kes,2306
|
|
2
|
-
toml_rs-0.0.6.dist-info/WHEEL,sha256=DyJBVhA1hlR1K33J-EVD6hJjYEhlXPD8lNx9_PF41TU,97
|
|
3
|
-
toml_rs-0.0.6.dist-info/licenses/UNLICENSE,sha256=pO9SJPWzhoS7yVUh8EuWMlwkAsA9o-yzXiMtgqmWKC8,1233
|
|
4
|
-
toml_rs/__init__.py,sha256=NIiAfcSc1whF7NT0jfypUpEACbx4_yfP1PATASZiQi8,1113
|
|
5
|
-
toml_rs/_toml_rs.cp314t-win_amd64.pyd,sha256=gYGCABtAVcfcCmyHM2dGDmPh9xtMM9NuUNhg0iE5sQ4,517120
|
|
6
|
-
toml_rs/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
toml_rs-0.0.6.dist-info/RECORD,,
|
|
File without changes
|