Registry / serialization / tomledit

tomledit

JSON →
library1.1.4pypypi✓ verified 87d ago

tomledit is a Python library designed for parsing and editing TOML files while meticulously preserving comments, whitespace, and the original order of elements. It is especially useful for managing configuration files where maintaining human-readable formatting is critical. The current version is 1.1.0, and it is actively maintained with releases made as needed.

pip install tomledit
INSTALL
IMPORT
SIG · TOMLEDIT
T
tomledit
serializationpythonv1.1.4
Install
1.6s avg
Import
—
Disk
17MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.1.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 1.8s
py 3.11
✓ —
✓ 1.65s
py 3.12
✓ —
✓ 1.5s
py 3.13
✓ —
✓ 1.6s
py 3.9
✕ build_error
✕ build_error
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Document
✓ from tomledit import Document
✗ from tomledit import TomlDocument
load
✓ from tomledit import load
dump
✓ from tomledit import dump

This quickstart demonstrates how to parse a TOML string, modify existing values, add new key-value pairs, and print the resulting document, all while preserving the original comments and formatting.

from tomledit import TomlDocument toml_content = """ # Main config [server] host = "localhost" # Server IP port = 8080 [database] type = "PostgreSQL" user = "admin" """ # Parse the TOML content doc = TomlDocument.parse(toml_content) print("--- Original Document ---") print(doc) # Modify values, preserving comments and format doc["server"]["host"] = "127.0.0.1" doc["database"]["user"] = "dbuser" # Add a new key to an existing table doc["database"]["password"] = "securepassword" print("\n--- Modified Document ---") print(doc)
tomledit --version
Debug
Known issues
gotchatomledit prioritizes format preservation for *existing* documents. When creating a new document entirely from a dictionary using `TomlDocument.from_dict()`, the resulting TOML string's formatting (e.g., indentation, spacing, table order) will use default styles and is not highly configurable to match specific aesthetic preferences.
fix
For highly specific formatting, it's often better to start with a template TOML file and load it, then make edits. If creating from a dict, accept the default formatting or manually adjust the output string if truly necessary.
affects: >=1.0.0
gotchaWhile `TomlDocument` mimics dictionary behavior, not all dictionary operations are fully format-preserving. Methods like `pop()`, `clear()`, or direct list manipulation (for arrays of tables) can lead to loss of associated comments or specific whitespace for the affected sections.
fix
For maximum format preservation, prefer direct item assignment (`doc['key'] = new_value`) for modifications. Avoid bulk dictionary operations on sub-structures if fine-grained control over original formatting and comments is critical.
affects: >=1.0.0
gotchatomledit parses TOML 1.0.0. While robust, feeding it significantly malformed TOML will raise a `TomlEditError`. It's an editor designed to work with valid TOML, not a parser designed to recover from arbitrary syntax errors.
fix
Ensure that the input TOML string or file is syntactically correct according to the TOML 1.0.0 specification before parsing with `TomlDocument.parse()` or `TomlDocument.load()`. Handle `TomlEditError` for expected invalid inputs.
affects: >=1.0.0
Upgrade
Version history
1.1.4latest on PyPI · released Apr 19, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
12
Amazon
1
OpenAI (training)
1
Resources