Skip to content

tomlrt

A format-preserving TOML reader and writer for Python.

Parse a document, edit it, dump it, and the bytes you didn't touch round-trip exactly — comments, whitespace, string style, and number formatting all intact.

Supports TOML 1.1.

import tomlrt

with open("pyproject.toml", "rb") as f:
    doc = tomlrt.load(f)

doc["project"]["version"] = "0.2.0"
doc["project"]["dependencies"].append("requests>=2")

print(tomlrt.dumps(doc))   # comments and layout are preserved

Where next

  • Quickstart — parse, edit, dump.
  • Building documents — construct a Document from scratch or from a dict.
  • Reading documents — typed accessors, dotted paths, and conversion back to plain Python.
  • Editing documents — dotted-path mutation, structural assignment, live views.
  • Comments — the comment API.
  • Layout — reshape a document's layout: sort keys, switch inline values between single- and multi-line, promote inline values to sections, and opt in to canonical formatting.
  • Errors — exception types.
  • API reference — full public surface.