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]) -> Dict[str, Any]: ...
Parse TOML via a string or file and return a python dictionary. The toml
argument may be a str
,
Path
or file object from open()
.
loads
def loads(toml: str) -> Dict[str, Any]: ...
Parse a TOML string and return a python dictionary. (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.6.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dfa25becabd44101cbdcd69438dc21c622728bc0fee2dd8a44ab791b4cac8a9 |
|
MD5 | 66928214afac460741eb1d9608467b24 |
|
BLAKE2b-256 | d87d8cf2ae3d892bda17681c6a210246c26acaadcc3b5f17f9d5c2ee2682a3b0 |
Hashes for rtoml-0.6.1-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd7e547a6128cdcc7d91a34f1bfd41f4d26daa7961a84c1df87b854cb038d022 |
|
MD5 | d9da5c2abefc24afc22a51fd3472894b |
|
BLAKE2b-256 | 55334e5b407098a3ff9b35b0d4b7fd72e76e77ad9d9458da2681210464c08c59 |
Hashes for rtoml-0.6.1-cp39-cp39-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df73f7d87f2136244b7ce433d1bc88d74272f83837b5f07fa2639995a0b06a7b |
|
MD5 | 8e42782e1ebe36f2336a53ad9d5cfa6b |
|
BLAKE2b-256 | e64c6dcd958694e977599d4ecfd73821627cd25dc5e413ed600a8c58a947c4f7 |
Hashes for rtoml-0.6.1-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d22bb3df0088550449b79bd441e2660d5e311fbbf5bbeaffe7f4e154bafe4b6c |
|
MD5 | 9a3fd0e0d4a4facb1d9cd6838471baa9 |
|
BLAKE2b-256 | 73e98aa01ac569be883d64187f77e62fc25efd586f3b9c80e291e837473959c2 |
Hashes for rtoml-0.6.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e42f48298641297498776b395d1cf7d76c7ba0609bcaec59c1e4924290eed9fc |
|
MD5 | b9e841efb80d043a46d616a63ed3234a |
|
BLAKE2b-256 | 816859bf2d68dfd3a8cf3746f574be38d0174151dcc9e44caa0261a0831f6dfc |
Hashes for rtoml-0.6.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8357b934f918af98a5b9d2a8d602e73b4e300d636b9210c75dac71988783202 |
|
MD5 | fe8f91fdf098eeac08470f12786a8519 |
|
BLAKE2b-256 | 13d3db1fe69f36d5c30d5f79bb9654234554a6fd66f55a48db9e63cf9beb966a |
Hashes for rtoml-0.6.1-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0724f592261ab5011b4c752cf31bf1e7a9fcb530ff6480f2640a720700b0b4a |
|
MD5 | 1d3c8283a109b974f09cd7a13931b3fe |
|
BLAKE2b-256 | b8790215493f2b04058e792cba47378f701aad10e150593e9ed82114c165e924 |
Hashes for rtoml-0.6.1-cp38-cp38-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 786fc4436725a28c3b521eaeba9a16458844534110bf05c377d166a9dd220595 |
|
MD5 | 37aff7563ab28256bdf2f56395e0f78c |
|
BLAKE2b-256 | 6cdbb1e9972cff417cc54d4616ca142fb3bda09c58891dc76d516481b18eab26 |
Hashes for rtoml-0.6.1-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9271f32115b407cff0b65f0f711a686f2ce5f89c17579120c1db92f468d10963 |
|
MD5 | bb25cd132d379665b94343a470624755 |
|
BLAKE2b-256 | 86b8cfbe35a3db10ff877d12710bbccd24b94b6a817e77a4e21d053479577148 |
Hashes for rtoml-0.6.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3ccd4e9d56e61e0cf822fc1506e756f420170f9ded2fac75b3ae922543d70d0 |
|
MD5 | ca5a04eee360e04b332a8998922206f2 |
|
BLAKE2b-256 | c352a5d89686433202aff6781ba59cdde90aeaa5c943eed30aa58fc961909f87 |
Hashes for rtoml-0.6.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa3f7392f5e081ccebdb78fb172723fe4f696b2fd6ba91939eb82b731da85dbb |
|
MD5 | ec09a9d7b49ae5ddece9fc97f1b1f48e |
|
BLAKE2b-256 | fe696383f2667ea8bb5e8c2730d25ad251c25070464050b2d752e03241118859 |
Hashes for rtoml-0.6.1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14b1336bd2c58e345f678b62efc9c92a92b7e77d73b148a5213a273277e093b1 |
|
MD5 | eee225254cec47d3b81daeb96f79e65f |
|
BLAKE2b-256 | 4c8d7e1da03e48c2acdf408c06f8cd5af808b5b9d2d4e610b680bac491f6cf68 |
Hashes for rtoml-0.6.1-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd342389b8a8e8eda8239ce6b8a6d7da07d027558b5a09e5a387a211e08148fb |
|
MD5 | 5bf05c339b497fbdab7598b3768292ae |
|
BLAKE2b-256 | 032e74ef1a9b5324c1b7d9ccf076c2c73d302fa3d995668b076cde6653696b72 |
Hashes for rtoml-0.6.1-cp37-cp37m-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4216e3b6c7494e0a4f83b5cfd93d4b168f440b8e01b8eb94ae3a3b1dd129707 |
|
MD5 | cdfa774fe847ae1d549b13ac700ebe45 |
|
BLAKE2b-256 | 70ce20a5bce36e2e95c34c8660fa4f96f5e03be15b802bfadab01bea157137b8 |
Hashes for rtoml-0.6.1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c77773b6bff6eeee612344d5eb16c971ce44b30ac097f2213be78f80f220df2b |
|
MD5 | 7c99c1a6ebed08a7a8aae046b7853aae |
|
BLAKE2b-256 | 071441147d49bf01493c9a22378e0751ead55b0c03e2fd30b263929c2d6cee9a |
Hashes for rtoml-0.6.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b807cc6f494b3070950d61f1289d11fa362d25aad45cfec6a80ea2ef64a701c |
|
MD5 | b9749f8134df7fb7a11969c9235237af |
|
BLAKE2b-256 | 2810b8fe298fc2ecd72550fb2edb45aad3d144ece4ab2cea92c61e7754efacd3 |