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 pure Python TOML libraries.
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.7.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3611a03cf4b534752689003eeaf47eb537cabbf2f6c4e396675ebc1bbe5cac4d |
|
MD5 | da741916741bd237af58c26e3ceab428 |
|
BLAKE2b-256 | 06a698f4359bd64cda1b19cd088d39beb3e20324db3cc347d07bd7e0f22bd6c0 |
Hashes for rtoml-0.7.0-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a993192d77daa6f176c0bc0618e1c7331baa9ce63bcf32e38bb411bf84a8463 |
|
MD5 | 45f2bb7220ed66394c4d7607017fd3a8 |
|
BLAKE2b-256 | 36548e372116d98155e0bd0d137a0b79e88b59ea664066c559c2f59249e9f98a |
Hashes for rtoml-0.7.0-cp39-cp39-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4671bcf02de6af6d831ee69a404023c8e77c89d27d81c4f7985e060ff631ddf6 |
|
MD5 | 0e1691098d78ab7e3942ea20e0a9baf5 |
|
BLAKE2b-256 | cace00c39ab365d917be896812d74e75844e1c215cdb63e877608c913298bdd9 |
Hashes for rtoml-0.7.0-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 162412ede29603f5fab4e8856719cd4500fddce586dc3da19dfa4051a1196bb8 |
|
MD5 | 0e0da3cd3bd8d4b00a27962a6c2349a0 |
|
BLAKE2b-256 | e260bc15d5545296211bac2993ebba64e9c495bd432e0e33ab34f4323d7081cf |
Hashes for rtoml-0.7.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c50aea7c10c6f88eddb58cbb7adaed230606f63890d2ea7214142b518ec5bd15 |
|
MD5 | 498a25f67dc5e9a69c3d4873efed1b58 |
|
BLAKE2b-256 | 4e3d8ca03c466df241dd9b6fea38a90a4d079ee12570aca7188face5e61fff2b |
Hashes for rtoml-0.7.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f706ac488d20e5c670704759e06bc412c7c63eff1c31db5f90d64a2607f0ebec |
|
MD5 | ec59d630a885cc91719f896ec52d0d12 |
|
BLAKE2b-256 | 6b7cf67ee3e24f5ec200775fa61e70df244083e7d80e433272bc2c06647ef312 |
Hashes for rtoml-0.7.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1059b61142a764655a8a1bb93261c9686d3812d922db97d1a4c0f245d22671e1 |
|
MD5 | a19b30de72dc7209db5f5ec6cf4258cb |
|
BLAKE2b-256 | 7c9494dac40720ccd8ec0f6151ac292fdca1c0a36534911d1e6b9cd3c37713c4 |
Hashes for rtoml-0.7.0-cp38-cp38-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06179b3907f54fe44bb17a37815888fb93b038ae8052de21e359e91075d13473 |
|
MD5 | 69f66b54c67c1b9f5b982da1c2971e77 |
|
BLAKE2b-256 | a365f6021f404916aea71dc152503925156d812a6736ccd38259ea1649f85e9c |
Hashes for rtoml-0.7.0-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b8bd824bf049a3b7c3facfc01eb26a29256153a427d715c797875ba0099278b |
|
MD5 | bc6a7d9a1179c2c861f432e0e41914c1 |
|
BLAKE2b-256 | b114aa41bac79beb2eed02b97ca003753db8796d3d2ff46351e3a57118cac8f8 |
Hashes for rtoml-0.7.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba65ffee4032a4ebdb3a62f120fccf72e3e5b1368883da38a29cb800f1f0ef1b |
|
MD5 | bb6d88b9db47f69c06a3a8690ca8af65 |
|
BLAKE2b-256 | a98e7870ef37bc62c39166156b752e3c00de9c089e94654da2d26ea85e5db18a |
Hashes for rtoml-0.7.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ae0a1aa740e6c64cab354a1c3f9a9343a64d2f68c97ab78d887bdc97e815ab9 |
|
MD5 | e678b572bc2d55e284408b3901e2beda |
|
BLAKE2b-256 | 9c3577fbea8f08639144ed2c9588e20feda6507f092bb7f1b212172529c507ec |
Hashes for rtoml-0.7.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c922be5808546d84018286877703211090065d86f517392bf956214916f47872 |
|
MD5 | 757b986a4d389a973f3bfad12d2f6575 |
|
BLAKE2b-256 | f754d7d03150794dd732bbbd8713d66bb4df7239690802a98831efe37ccf63e8 |
Hashes for rtoml-0.7.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b87ecc3c1c7a6d8ca72b141c41772d9cc10e6180182d0314d6e475f72da7ef57 |
|
MD5 | f9b13b2d4ce3033e59c9a91c7a190ddd |
|
BLAKE2b-256 | de03b6ea280073b6c68ff53d3d5e04db3ced76bedfe80b0d864015871953cb06 |
Hashes for rtoml-0.7.0-cp37-cp37m-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba027d9b061349c5561147235f01a3933a1bf29d0cb90896efa5f76bce843611 |
|
MD5 | 49a885206da1fbe5a3d975940ace147f |
|
BLAKE2b-256 | 32198b5bafff662470d04909963a7387f4e9700efd4f9051776410bd99edb254 |
Hashes for rtoml-0.7.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de6e902f78cc10164a00be8b708f13ff524d15f171dbc58a1fa8fa512a1f39f7 |
|
MD5 | 02398cda15f0dcff351dd1285f330f42 |
|
BLAKE2b-256 | ec4833101a85cbfe0a22abeb8dd00320e48b45dfd1d637e40b60f8dd022a40f7 |
Hashes for rtoml-0.7.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d89b09cbe78488a844b0555bc56de151d923d5afa43465e87b3ede9c232e9d7b |
|
MD5 | 2e30df00ff87f4d1b595f5dee905f0dd |
|
BLAKE2b-256 | d9fa62091fd7caf30761fdee51593a92496d04f7ebe571921c03f3ca09ed6e0a |