toml-rs 0.3.0__cp314-cp314-manylinux_2_17_aarch64.manylinux2014_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.
toml_rs/__init__.py ADDED
@@ -0,0 +1,19 @@
1
+ __all__ = (
2
+ "TOMLDecodeError",
3
+ "TOMLEncodeError",
4
+ "__version__",
5
+ "dump",
6
+ "dumps",
7
+ "load",
8
+ "loads",
9
+ )
10
+
11
+ from ._lib import (
12
+ TOMLDecodeError,
13
+ TOMLEncodeError,
14
+ __version__,
15
+ dump,
16
+ dumps,
17
+ load,
18
+ loads,
19
+ )
toml_rs/_lib.py ADDED
@@ -0,0 +1,106 @@
1
+ from collections.abc import Callable
2
+ from pathlib import Path
3
+ from typing import Any, BinaryIO, Literal, TextIO, TypeAlias
4
+
5
+ from ._toml_rs import (
6
+ _VERSION,
7
+ _dumps,
8
+ _loads,
9
+ )
10
+
11
+ __version__: str = _VERSION
12
+
13
+ TomlVersion: TypeAlias = Literal["1.0.0", "1.1.0"]
14
+
15
+ DEFAULT_TOML_VERSION = "1.0.0"
16
+
17
+
18
+ def load(
19
+ fp: BinaryIO,
20
+ /,
21
+ *,
22
+ parse_float: Callable[[str], Any] = float,
23
+ toml_version: TomlVersion = DEFAULT_TOML_VERSION,
24
+ ) -> dict[str, Any]:
25
+ toml_bytes = fp.read()
26
+ try:
27
+ toml_str = toml_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(toml_str, parse_float=parse_float, toml_version=toml_version)
32
+
33
+
34
+ def loads(
35
+ s: str,
36
+ /,
37
+ *,
38
+ parse_float: Callable[[str], Any] = float,
39
+ toml_version: TomlVersion = DEFAULT_TOML_VERSION,
40
+ ) -> dict[str, Any]:
41
+ if not isinstance(s, str):
42
+ msg = f"Expected str object, not '{type(s).__qualname__}'"
43
+ raise TypeError(msg)
44
+ return _loads(s, parse_float=parse_float, toml_version=toml_version)
45
+
46
+
47
+ def dump(
48
+ obj: Any,
49
+ /,
50
+ file: str | Path | TextIO,
51
+ inline_tables: set[str] | None = None,
52
+ *,
53
+ pretty: bool = False,
54
+ toml_version: TomlVersion = DEFAULT_TOML_VERSION,
55
+ ) -> int:
56
+ toml_str = _dumps(
57
+ obj,
58
+ inline_tables=inline_tables,
59
+ pretty=pretty,
60
+ toml_version=toml_version,
61
+ )
62
+ if isinstance(file, str):
63
+ file = Path(file)
64
+ if isinstance(file, Path):
65
+ return file.write_text(toml_str, encoding="utf-8")
66
+
67
+ return file.write(toml_str)
68
+
69
+
70
+ def dumps(
71
+ obj: Any,
72
+ /,
73
+ inline_tables: set[str] | None = None,
74
+ *,
75
+ pretty: bool = False,
76
+ toml_version: TomlVersion = DEFAULT_TOML_VERSION,
77
+ ) -> str:
78
+ return _dumps(
79
+ obj,
80
+ inline_tables=inline_tables,
81
+ pretty=pretty,
82
+ toml_version=toml_version,
83
+ )
84
+
85
+
86
+ class TOMLDecodeError(ValueError):
87
+ def __init__(self, msg: str, doc: str, pos: int, *args: Any) -> None:
88
+ msg = msg.rstrip()
89
+ super().__init__(msg)
90
+ lineno = doc.count("\n", 0, pos) + 1
91
+ if lineno == 1: # noqa: SIM108
92
+ colno = pos + 1
93
+ else:
94
+ colno = pos - doc.rindex("\n", 0, pos)
95
+ self.msg = msg
96
+ self.doc = doc
97
+ self.pos = pos
98
+ self.colno = colno
99
+ self.lineno = lineno
100
+
101
+
102
+ class TOMLEncodeError(TypeError):
103
+ def __init__(self, msg: str, *args: Any) -> None:
104
+ msg = msg.rstrip()
105
+ super().__init__(msg)
106
+ self.msg = msg
toml_rs/_toml_rs.pyi ADDED
@@ -0,0 +1,23 @@
1
+ from collections.abc import Callable
2
+ from typing import Any, Literal, TypeAlias
3
+
4
+ _VERSION: str
5
+
6
+ TomlVersion: TypeAlias = Literal["1.0.0", "1.1.0"]
7
+
8
+ def _loads(
9
+ s: str,
10
+ /,
11
+ *,
12
+ parse_float: Callable[[str], Any] = ...,
13
+ toml_version: TomlVersion = ...,
14
+ ) -> dict[str, Any]: ...
15
+
16
+ def _dumps(
17
+ obj: Any,
18
+ /,
19
+ inline_tables: set[str] | None = None,
20
+ *,
21
+ pretty: bool = False,
22
+ toml_version: TomlVersion = ...,
23
+ ) -> str: ...
toml_rs/py.typed ADDED
@@ -0,0 +1 @@
1
+ # Marker file for PEP 561
@@ -0,0 +1,151 @@
1
+ Metadata-Version: 2.4
2
+ Name: toml-rs
3
+ Version: 0.3.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: Bug Tracker, https://github.com/lava-sh/toml-rs/issues
25
+ Project-URL: Homepage, https://github.com/lava-sh/toml-rs
26
+ Project-URL: Source, https://github.com/lava-sh/toml-rs
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
+ [![PyPI License](https://img.shields.io/pypi/l/toml_rs.svg?style=flat-square)](https://pypi.org/project/toml_rs/)
35
+
36
+ [![Monthly downloads](https://img.shields.io/pypi/dm/toml_rs.svg?style=flat-square)](https://pypi.org/project/toml_rs/)
37
+ [![Github Repository size](https://img.shields.io/github/repo-size/lava-sh/toml-rs?style=flat-square)](https://github.com/lava-sh/toml-rs)
38
+
39
+ [![Python version](https://img.shields.io/pypi/pyversions/toml_rs.svg?style=flat-square)](https://pypi.org/project/toml_rs/)
40
+ [![Implementation](https://img.shields.io/pypi/implementation/toml_rs.svg?style=flat-square)](https://pypi.org/project/toml_rs/)
41
+
42
+ </div>
43
+
44
+ ## Features
45
+
46
+ * The fastest TOML parser in Python (see [benchmarks](https://github.com/lava-sh/toml-rs/tree/main/benchmark))
47
+
48
+ * Drop-in compatibility with most [`tomllib`](https://docs.python.org/3/library/tomllib.html) use cases (see [below](#differences-with-tomllib))
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ # Using pip
54
+ pip install toml-rs
55
+
56
+ # Using uv
57
+ uv pip install toml-rs
58
+ ```
59
+
60
+ ## Examples
61
+
62
+ ```python
63
+ import tomllib
64
+ from pprint import pprint
65
+
66
+ import toml_rs
67
+
68
+ toml = """\
69
+ title = "TOML Example"
70
+
71
+ [owner]
72
+ name = "Tom Preston-Werner"
73
+ dob = 1979-05-27T07:32:00-08:00
74
+
75
+ [database]
76
+ enabled = true
77
+ ports = [ 8000, 8001, 8002 ]
78
+ data = [ ["delta", "phi"], [3.14] ]
79
+ temp_targets = { cpu = 79.5, case = 72.0 }
80
+
81
+ [servers]
82
+ [servers.alpha]
83
+ ip = "10.0.0.1"
84
+ role = "frontend"
85
+ [servers.beta]
86
+ ip = "10.0.0.2"
87
+ role = "backend"
88
+ """
89
+
90
+ tomllib_loads = tomllib.loads(toml)
91
+ toml_rs_loads = toml_rs.loads(toml)
92
+ toml_rs_dumps = toml_rs.dumps(toml_rs_loads)
93
+
94
+ assert tomllib_loads == toml_rs_loads
95
+
96
+ print("toml_rs.loads:")
97
+ pprint(toml_rs_loads)
98
+ print("toml_rs.dumps:")
99
+ print(toml_rs_dumps)
100
+ ```
101
+
102
+ ## Differences with [`tomllib`](https://docs.python.org/3/library/tomllib.html)
103
+
104
+ 1. More understandable errors
105
+
106
+ ```python
107
+ import tomllib
108
+
109
+ t = """\
110
+ x = 1
111
+ y = 2
112
+ v =
113
+ """
114
+ print(tomllib.loads(t))
115
+ # tomllib.TOMLDecodeError: Invalid value (at line 3, column 5)
116
+ ```
117
+
118
+ ```python
119
+ import toml_rs
120
+
121
+ t = """\
122
+ x = 1
123
+ y = 2
124
+ v =
125
+ """
126
+ print(toml_rs.loads(t))
127
+ # toml_rs.TOMLDecodeError: TOML parse error at line 3, column 5
128
+ # |
129
+ # 3 | v =
130
+ # | ^
131
+ # string values must be quoted, expected literal string
132
+ ```
133
+
134
+ 2. Supports serialization (`toml_rs.dumps` and `toml_rs.dump`)
135
+
136
+ ```python
137
+ from pathlib import Path
138
+
139
+ import toml_rs
140
+
141
+ data = {
142
+ "title": "TOML Example",
143
+ "owner": {"name": "Alice", "age": 30},
144
+ }
145
+
146
+ print(toml_rs.dumps(data))
147
+
148
+ toml_rs.dump(data, Path("example.toml"))
149
+ # or `toml_rs.dump(data, "example.toml")`
150
+ ```
151
+
@@ -0,0 +1,9 @@
1
+ toml_rs/__init__.py,sha256=dRwvPSgcaZjVowudfW6q_UGwDG1f6WLjV99NePVGkW4,253
2
+ toml_rs/_lib.py,sha256=xHMj-pdpEaeOBiBVFaE9kBxEh5W35TDwASi06pLmQPo,2602
3
+ toml_rs/_toml_rs.cpython-314-aarch64-linux-gnu.so,sha256=vUuE8jtk-xCZlzTyI1sgemwYt4zr_5Xxpx8fiL8kUis,866384
4
+ toml_rs/_toml_rs.pyi,sha256=slZGAC5NggSMGqA_tooNhdZDJaS_o8_MbqCebPWl22A,454
5
+ toml_rs/py.typed,sha256=8ZJUsxZiuOy1oJeVhsTWQhTG_6pTVHVXk5hJL79ebTk,25
6
+ toml_rs-0.3.0.dist-info/METADATA,sha256=th7K2yjkl7S6TAmtyZ1K8P35R6uN267WeleiZWdpEUw,3832
7
+ toml_rs-0.3.0.dist-info/WHEEL,sha256=Fx-7UOgjfhtK3XXmysArRGq3lEQiAORUMl6jtPUmCMs,149
8
+ toml_rs-0.3.0.dist-info/licenses/UNLICENSE,sha256=yiq99pWITHfqS0pbZMp7cy2dnbreTuvBwudsU-njvIM,1210
9
+ toml_rs-0.3.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.11.5)
3
+ Root-Is-Purelib: false
4
+ Tag: cp314-cp314-manylinux_2_17_aarch64
5
+ Tag: cp314-cp314-manylinux2014_aarch64
@@ -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/>