A better TOML library for python implemented in rust.
Project description
rtoml
A better TOML library for python implemented in rust.
Why Use rtoml
- Correctness: rtoml is based on the widely used and very stable toml-rs library, it passes all the standard TOML tests as well as having 100% coverage on python code. Other TOML libraries for python I tried all failed to parse some valid TOML.
- Performance: see benchmarks - rtoml is much faster than other TOML libraries for python.
Install
Requires python>=3.7
, binaries are available from pypi for linux, macos and windows,
see here.
pip install rtoml
If no binary is available on pypi for you system configuration; you'll need rust nightly and
setuptools-rust
installed before you can install rtoml.
Usage
load
def load(toml: Union[str, Path, TextIO]) -> Any: ...
Parse TOML via a string or file and return a python object. The toml
argument may be a str
,
Path
or file object from open()
.
loads
def loads(toml: str) -> Any: ...
Parse a TOML string and return a python object. (provided to match the interface of json
and similar libraries)
dumps
def dumps(obj: Any, *, pretty: bool = False) -> str: ...
Serialize a python object to TOML.
If pretty
is true, output has a more "pretty" format.
dump
def dump(obj: Any, file: Union[Path, TextIO], *, pretty: bool = False) -> int: ...
Serialize a python object to TOML and write it to a file. file
may be a Path
or file object from open()
.
If pretty
is true, output has a more "pretty" format.
Example
from datetime import datetime, timezone, timedelta
import rtoml
obj = {
'title': 'TOML Example',
'owner': {
'dob': datetime(1979, 5, 27, 7, 32, tzinfo=timezone(timedelta(hours=-8))),
'name': 'Tom Preston-Werner',
},
'database': {
'connection_max': 5000,
'enabled': True,
'ports': [8001, 8001, 8002],
'server': '192.168.1.1',
},
}
loaded_obj = rtoml.load("""\
# This is a TOML document.
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00 # First class dates
[database]
server = "192.168.1.1"
ports = [8001, 8001, 8002]
connection_max = 5000
enabled = true
""")
assert loaded_obj == obj
assert rtoml.dumps(obj) == """\
title = "TOML Example"
[owner]
dob = 1979-05-27T07:32:00-08:00
name = "Tom Preston-Werner"
[database]
connection_max = 5000
enabled = true
server = "192.168.1.1"
ports = [8001, 8001, 8002]
"""
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for rtoml-0.5.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 828673456def5c81e048739a213e7bd600657521a2aa20aa4ca2e9e39d24666b |
|
MD5 | fe2ce554e9a5b47475bc34c441efb901 |
|
BLAKE2b-256 | 6028e82ded2851ddcc1e8e9e783eda2a37ca001939c75748e77fbc891634a08e |
Hashes for rtoml-0.5.0-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b29cf20b3db7cd11ca560f83b764ca43f0b6d59f5523e843797ce66e1b8bdaf4 |
|
MD5 | a94a0daeac7bc0e01fba7dabfc90f9de |
|
BLAKE2b-256 | 74aff654c2babffb2dfe5e4583f4e566a48fb27105af44a04fb514454e394d41 |
Hashes for rtoml-0.5.0-cp39-cp39-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e89af0584945ac784f13744d1d1410e53d9070c680dd53ecbfb6fe4d11d10dbb |
|
MD5 | cd404134c0c6822096b230c21a2e5723 |
|
BLAKE2b-256 | 15dfd957aaee69c0008dd3e47b2a835068e74b338bc3060cf225cdff0a2ec8a9 |
Hashes for rtoml-0.5.0-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5216a177ad22247675886dbb33b15f4e080633749a455d2887ef9609e94d32de |
|
MD5 | afa1749ea079dedcaddd6d4cc8ad978d |
|
BLAKE2b-256 | 90545dc6460fc4af0701b8651fba910a15fc8110cad5937b58f5ff9961227e36 |
Hashes for rtoml-0.5.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73b5a9b83a69543f4147f9f19aa4b39da3c850000644672b5386740ecadd016c |
|
MD5 | 4cc3912eb05d367a9f4ca37f548351e4 |
|
BLAKE2b-256 | b567a9045fcf6228aed9ee61a9d9cf0ec9bef30a03098f3b4e923c241252742d |
Hashes for rtoml-0.5.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 044780b5e5fa4434c4f3e36d05a65d7ebe345529c69f38ac54fd45e0dc59283e |
|
MD5 | cfe621f6f1ec41f57b46fdf084e5db19 |
|
BLAKE2b-256 | 357e5baebc42228b980f595659261d898156786015af45214e15fad4dbf27b3f |
Hashes for rtoml-0.5.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff58b95325a49dd1b6d41a997da9aa496db970c66e80a242dd8ca9cc4a613502 |
|
MD5 | 62eb72291b709a50071a435fcc60be26 |
|
BLAKE2b-256 | b27a763cdb9e14f37c39610f7878241515b542fe6865c009632c884769f0ef40 |
Hashes for rtoml-0.5.0-cp38-cp38-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e781994d1884bbb956b33de6cd9c0b73aadfaad8cb5a520482edb98e52ae735 |
|
MD5 | 9a250725cb591a53e521b79d57dec20f |
|
BLAKE2b-256 | d1a67e50659a56fb0eddff2727f8f6033483ba3e3a64a40de72e878b78663182 |
Hashes for rtoml-0.5.0-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d431bd5cab786ed23397c7d3d613c8c4119fa85ebbc3b03314ac74e38a960f5 |
|
MD5 | 8d08f5a07b67fa53012bdafda47c80b2 |
|
BLAKE2b-256 | 92fdec154b3ce0481ccbab67fb264075aae664e229a3a6231e292b0fc29bf9b8 |
Hashes for rtoml-0.5.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3844a641f20fd9d29bb4d07012c4b88432eca00e4b319ac6c16504b501eac3a |
|
MD5 | 67da642d03b5ad3955d899a4fba6f7e3 |
|
BLAKE2b-256 | b75ff531bfde866b9851816b55d7a015a69fbba3b64c9e2e09dc459240d6182a |
Hashes for rtoml-0.5.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9373ca569c6cbf094e4989bdfd45ab063e5b7b65f74c5a0013214bcffe00016e |
|
MD5 | a79784e432b0d3c843ed94ade0129e4c |
|
BLAKE2b-256 | 44191dd4a4e78beb8b5d9bdaaa9f7782da9abd49a2d1d773f5dc858066e1f4ba |
Hashes for rtoml-0.5.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83b8d2b54689b8a46c8bc3f8e02f20e75922820f063360d2ef3ffefb1347b626 |
|
MD5 | 1373346aba03a7ef608983f6f928cd90 |
|
BLAKE2b-256 | e6fb8cabe32071932cdc8bddc4c26638f9f8a3f09c2525f5cd4f54a0ada0df17 |
Hashes for rtoml-0.5.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f66a3249025cd45a6193c6a39f72b03c5fb8aeee6b2a88206408c466635fe9e4 |
|
MD5 | 17e47cfac3484f1b5def27e8a78c21eb |
|
BLAKE2b-256 | 133f40538f669315b689fc13c97179cbf82e737dfc8ca7e310d2f28b97ee1017 |
Hashes for rtoml-0.5.0-cp37-cp37m-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff63e85f168ddb46b5992d9fca554a113d16d534f17f861e847ad93c530d3111 |
|
MD5 | 06b9b14a538220acf6346b4f243a49c3 |
|
BLAKE2b-256 | e2e7399d1cdca8f0adc14aaf2633f369beb9d54617f7d367d2e52fd786fd4989 |
Hashes for rtoml-0.5.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72259154c5041ea168748ccfd64cc7e58b514d1e28d2dd897f9386676899ffe6 |
|
MD5 | a0aa8b5d8478fa7ecff06222a06c3ef6 |
|
BLAKE2b-256 | aa0c8ba2415620912f14e14f4b127af7c24b985b0a96337bd7656cf00d43e9a1 |
Hashes for rtoml-0.5.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac2955858bf1ef467648b896c1dfc6fc660301302599ed810181846f13b40351 |
|
MD5 | 267eb74617152319b987c9e1e1f1a9bb |
|
BLAKE2b-256 | 96acec4363dcbd6dfa42bf330192cb0a1c5da04de345ad02196c761efcf00eb8 |