Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?


Failed to load latest commit information.
Latest commit message
Commit time


Actions Status Coverage pypi versions 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 - rtoml is much faster than pure Python TOML libraries.


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 stable installed before you can install rtoml.



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().


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)


def dumps(obj: Any, *, pretty: bool = False) -> str: ...

Serialize a python object to TOML.

If pretty is true, output has a more "pretty" format.


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.


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': '',

loaded_obj = rtoml.load("""\
# This is a TOML document.

title = "TOML Example"

name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00 # First class dates

server = ""
ports = [8001, 8001, 8002]
connection_max = 5000
enabled = true

assert loaded_obj == obj

assert rtoml.dumps(obj) == """\
title = "TOML Example"

dob = 1979-05-27T07:32:00-08:00
name = "Tom Preston-Werner"

connection_max = 5000
enabled = true
server = ""
ports = [8001, 8001, 8002]