Style-preserving TOML library for Python
Find a file
Gal Be 3cdcbde4f3
Speed up parsing of comments by scanning the comment text in bulk (#723)
The comment body was read one character at a time, with a control-char
check and a Source.inc() call per character. Scan it with
Source.advance_until() up to the line break or the first control char
that is invalid in a comment, as the string-body fast paths already do.
The output and the errors do not change.
2026-11-27 09:13:56 +08:00
.github chore: ask contributors and agents to check for duplicate open PRs 2026-10-27 10:01:29 +08:00
docs chore(deps): bump soupsieve from 2.9 to 4.0 in /docs (#713) 2026-11-22 20:24:33 +08:00
tests Speed up parsing of comments by scanning the comment text in bulk (#723) 2026-11-27 09:13:56 +08:00
tomlkit Speed up parsing of comments by scanning the comment text in bulk (#723) 2026-11-27 09:13:56 +08:00
.coveragerc Lint properly 2020-07-27 22:08:17 +02:00
.gitignore Add lock file 2020-01-24 16:41:54 +01:00
.gitmodules feat(spec): update to toml spec v1.1 (#456) 2026-02-07 11:11:54 +08:00
.pre-commit-config.yaml [pre-commit.ci] pre-commit autoupdate (#718) 2026-11-24 10:37:55 +08:00
.readthedocs.yaml fix: linter errors caused by black 2024-04-30 08:45:32 +08:00
AGENTS.md docs: add AGENTS.md requiring Human Attestation for all PRs 2026-11-09 17:03:46 +08:00
CHANGELOG.md Speed up parsing of comments by scanning the comment text in bulk (#723) 2026-11-27 09:13:56 +08:00
LICENSE Add LICENSE 2018-07-09 21:21:03 -05:00
poetry.lock chore(deps-dev): bump urllib3 from 2.6.3 to 2.8.0 (#638) 2026-10-12 17:45:33 +08:00
pyproject.toml Release 0.15.3 (#719) 2026-11-24 15:16:58 +08:00
README.md Fix ParseError when a sub-table extends an array of tables out of order (#498) 2026-06-23 15:25:05 +08:00
tox.ini fix: Remove 3.7 from the CI matrix 2024-07-10 16:04:54 +08:00
uv.lock Release 0.15.3 (#719) 2026-11-24 15:16:58 +08:00

GitHub Release PyPI Version Python Versions License
Tests

TOML Kit - Style-preserving TOML library for Python

TOML Kit is a 1.1.0-compliant TOML library.

It includes a parser that preserves all comments, indentations, whitespace and internal element ordering, and makes them accessible and editable via an intuitive API.

You can also create new TOML documents from scratch using the provided helpers.

Part of the implementation has been adapted, improved and fixed from Molten.

Usage

See the documentation for more information.

Limitations

tomlkit preserves the original layout of a document, with one exception: a sub-table that extends an array of tables out of order — for example a [fruit.apple.texture] header that appears after [[fruit]] with an unrelated table in between — is normalized into the array's last element when the document is re-serialized, rather than kept at its original position. The data is preserved; only the physical placement of that sub-table changes.

Installation

If you are using uv, you can add tomlkit to your pyproject.toml file by using:

uv add tomlkit

Or just:

uv pip install tomlkit

If not, you can use pip:

pip install tomlkit

Running tests

Please clone the repo with submodules with the following command:

git clone --recurse-submodules https://github.com/python-poetry/tomlkit.git

The toml-test submodule is required for running the tests.

You can then run the tests with

poetry run pytest -q tests