TOML Kit
TOML Kit is a style-preserving TOML library for Python, currently at version 0.14.0. It offers a parser that maintains comments, indentations, whitespace, and internal element ordering, providing an intuitive API for accessing and editing TOML files. The library is actively maintained with regular updates, as seen in its recent releases.
Warnings
- breaking In version 0.13.0, test failures with Python 3.13.0a4 were fixed, which may affect compatibility with earlier versions of Python 3.13.
- deprecated The 'loads' function is deprecated in favor of 'parse' for parsing TOML strings.
- gotcha When modifying TOML documents, ensure that changes are made through the provided API to preserve formatting and comments.
Install
-
pip install tomlkit
Imports
- parse
from tomlkit import parse
- dumps
from tomlkit import dumps
- table
from tomlkit import table
Quickstart
from tomlkit import parse, dumps, table
content = """[table]
foo = "bar" # String
"""
doc = parse(content)
doc['table']['baz'] = 13
tab = table()
tab.add('array', [1, 2, 3])
doc['table2'] = tab
dumps(doc)