Skip to main content

A better TOML library for python implemented in rust.

Project description

rtoml

Actions Status Coverage pypi license

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) -> str: ...

Serialize a python object to TOML.

dump

def dump(obj: Any, file: Union[Path, TextIO]) -> int: ...

Serialize a python object to TOML and write it to a file. file may be a Path or file object from open().

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for rtoml, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size rtoml-0.3.0-cp37-cp37m-macosx_10_6_intel.whl (259.6 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size rtoml-0.3.0-cp37-cp37m-manylinux1_i686.whl (902.0 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size rtoml-0.3.0-cp37-cp37m-manylinux1_x86_64.whl (826.6 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size rtoml-0.3.0-cp37-cp37m-manylinux2010_i686.whl (902.0 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size rtoml-0.3.0-cp37-cp37m-manylinux2010_x86_64.whl (826.6 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size rtoml-0.3.0-cp37-cp37m-win_amd64.whl (208.6 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size rtoml-0.3.0-cp38-cp38-macosx_10_9_x86_64.whl (259.6 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size rtoml-0.3.0-cp38-cp38-manylinux1_i686.whl (902.0 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size rtoml-0.3.0-cp38-cp38-manylinux1_x86_64.whl (826.5 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size rtoml-0.3.0-cp38-cp38-manylinux2010_i686.whl (902.0 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size rtoml-0.3.0-cp38-cp38-manylinux2010_x86_64.whl (826.5 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size rtoml-0.3.0-cp38-cp38-win_amd64.whl (208.6 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size rtoml-0.3.0.tar.gz (6.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page