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 tomleditVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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.
No dependency data recorded yet.