skillfed

tomlrt

A format-preserving TOML reader and writer for Python.

tomlrt v2.2.2 93.1K downloads/30d#13,403 on PyPI7
Permissive license MIT Active released

What it is and what it does

tomlrt is a TOML parser and writer that treats formatting as data rather than noise. When you load a TOML file, edit it, and dump it back, every byte you didn't touch stays exactly as it was—comments, blank lines, indentation, quote style, and number formatting all round-trip intact. This makes it ideal for tools that need to modify configuration files programmatically while preserving human-written structure and intent.

The package supports TOML 1.1 and exposes both a file-based API (load/dump) and a programmatic one (Document class for building documents from scratch). It depends only on typing-extensions, keeping the install lightweight. The implementation is pure Python, distributed as a wheel, and requires Python 3.10 or later.

Use it for:

  • Updating version strings or dependencies in pyproject.toml while keeping existing comments and formatting intact.
  • Building configuration management tools that edit TOML files without destroying developer-written structure.
  • Programmatically modifying application config files where preserving layout matters for readability or version control diffs.
  • Creating TOML editors or linters that need to round-trip documents without lossy parsing.
  • Generating new TOML documents from scratch using the Document API when format preservation isn't required.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Reads and writes TOML files while preserving formatting, comments, whitespace, and string styles exactly as they appear in the original document.

Yes. tomlrt solves a real problem—standard TOML parsers discard formatting, making them unsuitable for editing user-facing config files. The package is actively maintained, has no known vulnerabilities, carries a permissive MIT license, and installs with minimal friction. Use it whenever you need to read, modify, and write TOML while respecting the original document's structure.

Install

tomlrt on PyPI

pip

pip install tomlrt

uv

uv add tomlrt

poetry

poetry add tomlrt

Installing tomlrt

Before you install

Low friction: pure Python wheel, single lightweight dependency (typing-extensions), active maintenance with a release 1 day old.

License in practice

MIT license permits unrestricted use, modification, and distribution in both open-source and commercial projects.

Quickstart

import tomlrt

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

doc["project"]["version"] = "0.2.0"
print(tomlrt.dumps(doc))

Requires Python 3.10 or later.

Verify before relying

  • Whether round-trip fidelity holds for all TOML 1.1 edge cases (inline tables, nested structures, escape sequences).
  • Performance characteristics on large configuration files (parsing speed, memory usage).
  • Behavior when modifying deeply nested structures or adding new keys not in the original document.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 1 — typing-extensions
Maintenance actively maintained — 1 days since the last release
Last repo commit
First released
Downloads 93,055/month — #13,403 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: tomlrt-2.2.2-py3-none-any.whl

Keywords: config, configuration, format-preserving, pyproject, round-trip, toml, toml-parser, toml-writer, tomlrt

Intended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Typing :: Typed

Tags

toml parser preserves formattinground-trip toml reader writerformat-preserving config parsertoml editor with comments intactpyproject.toml round-triptoml with whitespace preservationlossless toml manipulation
config-managementround-trip-parsingformat-preserving

More Markup packages