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.6.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d717ddd0e8e651b7de2d9e0367277fc30d475d7ca024f9f2d41b4298ece71df |
|
MD5 | 4d55e0274b5c10a36297d425dae85d4f |
|
BLAKE2b-256 | 517c890f9465ed554db9c298ee4add26b6cc745a1f459082e4b22baf8400d16e |
Hashes for rtoml-0.6.0-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a3b0c6d102020ad58b383e133c4b05770f39ef662bf494ad691b8c313cdb85b |
|
MD5 | aa1f4a879994acfd1a5f56478d3e8529 |
|
BLAKE2b-256 | ee33b81ff8303181a6a3aea4a228ffa35a4a3c320dde5b2a129590a8f27e359b |
Hashes for rtoml-0.6.0-cp39-cp39-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf865d7376a1b580417342a0cf9e01b31cef739eb177581cfbea4d33b9cbfc1f |
|
MD5 | 23a6fc6d8955f00ce2be9ad48049dac9 |
|
BLAKE2b-256 | a8909e5348f52dd632cbbe9767c38429f9384640070a637fe1cdd5a77591e1b4 |
Hashes for rtoml-0.6.0-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf809b80ad309fd14dc1c74b781e9899e71dd8587d86fc31c7bd1e491425c1b4 |
|
MD5 | 396c4b30c14ee6dec3b54d632b130bf8 |
|
BLAKE2b-256 | c2e1a2b4430d176680198e6a19ae09f4da6104093e5029edee99379acdfc0ce4 |
Hashes for rtoml-0.6.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d0f6bdb42142cfb8ba8744dbbdaca2cd9d392836f6179a2b63e81d77d26a771 |
|
MD5 | fb8fe4a06aa6dbd27ee76f8cd6fdfaa1 |
|
BLAKE2b-256 | b8789a9a67b58499d5db12e4ef039c238538b9f7bfcbc53e1b6c97a84edb9e6d |
Hashes for rtoml-0.6.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b563e21d011481454ed4bc11884dd4150896fbe0c37888c3ec7ab81a789fba90 |
|
MD5 | 47bf0e67f5d6ba812343516391eab4ed |
|
BLAKE2b-256 | 4641743896bae99c535c62be28734efd0f616c7e70eed30d2fc6ba2bfa0a4116 |
Hashes for rtoml-0.6.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4735ec4e14c9ae779b34f903e33ef6e3b4d3b9d21c3f2eb69e8d1c300bba479d |
|
MD5 | 6127e1b089266136694eb9e065e746c6 |
|
BLAKE2b-256 | f744713e3a356be2ddeac37e3be504be83e2d1a1129b4490026dec2255ce8c34 |
Hashes for rtoml-0.6.0-cp38-cp38-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01b650fa8c37d0021b02921eabff34bd9b0544474112e631a5ec969d2d3c70ea |
|
MD5 | 9d676e20753229e49f5fdb22cf6882f5 |
|
BLAKE2b-256 | e83a706b0701909945db718551d3c6dc5a0931a561b0b3f70fcffd04f19da39c |
Hashes for rtoml-0.6.0-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 747ff3fb307114344b03a5e94c2e9a82b010c2c38ef247748d6fa6c0bb74dde3 |
|
MD5 | f6ab7f17640f37c4e174f79d1ce942f4 |
|
BLAKE2b-256 | 71937506764bb18cdd21b7c742ed83c0bf74226d0c08791c765c35fb111524b0 |
Hashes for rtoml-0.6.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8042a65e596147dfab4af9dccae53c24e0ffafa1cd3efd7b176f6fa2b08f09a5 |
|
MD5 | f15f394ede5b076fd752f8264cedb7bb |
|
BLAKE2b-256 | b83a35c57198f403ef9328b5d37400f5a7d6bfbb7261d920517cf6f0dad95d61 |
Hashes for rtoml-0.6.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd19fe676a7c8301a1c1fc8d340d0e6cfbeb1026135b74e620b3d33ad1098416 |
|
MD5 | 5d95626209ad6c7572a2ad1362de9b50 |
|
BLAKE2b-256 | dbbcd58e8f8ed53c71d7ec8f503692b6d3763040217ba5325cc5e30c0c1fea50 |
Hashes for rtoml-0.6.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad3afe1499ab7c1835b04ad407c180822f9f17a1acbbe2a227c312af44e72961 |
|
MD5 | 6dcc2b6b4f385b90b6a4b9e376befa50 |
|
BLAKE2b-256 | 8926f92c17149cc57a51f00e7de180a1e5323f97480fd66dd8fe75d21920c3a3 |
Hashes for rtoml-0.6.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7108570b6e7bd26b3eb69e4fdf30686bbc33eccc86a9bfb928c1f78baac70dd |
|
MD5 | 70798c2ef4d44eaffc5c784c299e4da5 |
|
BLAKE2b-256 | fa7d6f7c1de89f239fada408aa46e8f0b4ba1cef40a935d884ca195260bae788 |
Hashes for rtoml-0.6.0-cp37-cp37m-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 969d2166e7a3eed67a83b7f31ba78c2187ca2d7c7f37d9bd49d92ab45c9c6522 |
|
MD5 | 20e5a9ff912d5c037d3498b7e0a893b7 |
|
BLAKE2b-256 | 9d71478c224d81a28e3d1e34cddfd5135761c939471a4c4d161658f59fb96d82 |
Hashes for rtoml-0.6.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bab54fc6824f1fff125754f7f7036a5aec9ad9a36ba413963caa15d1f9161c9f |
|
MD5 | ae96bf2e96dd9bd23c84a4421ece4420 |
|
BLAKE2b-256 | ebf4f00a87aab7b263924a9aaa925338368b55d591918c0da205b39128e4e80c |
Hashes for rtoml-0.6.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 509da86c98c2d912e6bfafeda0f0317216262fc71f8f0a2624b1de0ca2174428 |
|
MD5 | 499af84d29b2449c31d24347f1363d0c |
|
BLAKE2b-256 | 2caaa2fdfc80a78704f39e4c17087b3c00bea6e9903d2d0079d633e8afecba33 |