tomlkit

Style-preserving TOML parser and writer for Python that keeps comments, whitespace, and ordering intact

Library
PyPI
v0.15.1
843stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
86/100Excellent
Development Activity100
Maintenance96
Community60
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
84/100Excellent
Architecture85
Code Quality88
Innovation82
Learning Curve80

tomlkit is a 1.1.0-compliant TOML library for Python built around a core idea most parsers ignore: round-tripping a document should not destroy how a human wrote it. Parsing a file with tomlkit produces a tree of typed items that remember their original comments, indentation, and key ordering, so editing a single value and re-serializing the document yields a diff limited to that value instead of a fully reformatted file. It also exposes helpers for building brand-new TOML documents programmatically from plain Python values.

Originally built for the Poetry package manager to safely edit pyproject.toml files, tomlkit has become the de facto choice anywhere a tool needs to read and rewrite TOML config without clobbering a user’s formatting choices - dependency managers, linters, and CLI scaffolding tools among them.

What You Get

  • A style-preserving parser (tomlkit.parse / tomlkit.load) that retains comments, whitespace, and item ordering
  • A TOMLDocument object model with typed items (Table, Array, InlineTable, DateTime, etc.) that mirror TOML’s grammar
  • Builder helpers (tomlkit.document, tomlkit.table, tomlkit.array, item()) for constructing new documents from scratch
  • Full TOML 1.1.0 compliance validated against the upstream toml-test conformance suite
  • A dict-like API (__getitem__/__setitem__, .unwrap()) so documents can be used like ordinary Python mappings

Common Use Cases

  • Programmatically editing pyproject.toml or similar config files during automated dependency or version bumps without rewriting the whole file
  • Building CLI tools (like Poetry) that read a TOML config, change one field, and save it back with the user’s original formatting untouched
  • Converting Python data structures into new, well-formatted TOML documents for generated configuration
  • Validating or migrating TOML files against the 1.1.0 spec as part of a linting or codemod pipeline

Under The Hood

Architecture - tomlkit’s core is a layered document model: source.py implements a cursor-based character reader, parser.py walks that stream into a Container (container.py), which holds an ordered mapping of Key objects to Item instances defined in items.py (Table, Array, InlineTable, String, DateTime, etc.). Every item stores its own Trivia (leading comment/whitespace) alongside its value, which is what lets TOMLDocument.as_string() reconstruct byte-for-byte output for anything the user didn’t touch. api.py is the thin public surface (parse, dumps, load, document, table, array, item) that wires these pieces together into the functions users actually call. Tech Stack - Pure Python with no runtime dependencies, targeting Python 3.9+; the project uses Poetry for packaging, ruff for linting (with isort, bugbear, comprehensions rule sets), mypy in strict mode for type-checking, and Sphinx/furo for documentation. Code Quality - The tests/ directory covers parser edge cases, item construction, document round-tripping, and file I/O (test_parser.py, test_items.py, test_toml_document.py, test_build.py, test_write.py), plus a dedicated test_toml_tests.py that runs the project against the language-agnostic toml-test submodule for spec conformance; mypy strict mode and typed _types.py definitions give the codebase consistent typing throughout. API Design - The public API is intentionally small and mirrors Python’s built-in json/toml module conventions (loads/dumps/load/dump), so anyone familiar with stdlib serialization modules can be productive immediately, while power users can drop into the typed item tree for fine-grained document construction.

Used by 7 apps in this directory

C++
69%
Apache 2.0

ClickHouse

Databases · Analytics · Data Engineering

49,325

Open-source column-oriented database that delivers real-time analytical queries on petabyte-scale data with millisecond latency.

View details
95
Repo Health
90
Technical
68
Dependency
Built with
C++69%
Python13%
Updated today
Python
91%
MIT

Cronboard

Developer Tools · Devops

1,437

A keyboard-driven terminal dashboard for managing cron jobs on local machines and remote servers via SSH.

View details
76
Repo Health
74
Technical
75
Dependency
Built with
Python91%
Updated 3 weeks ago
Python
80%
Apache 2.0

headroom

AI Development · Developer Tools

66,835

Compress everything your AI agent reads — tool outputs, logs, RAG chunks, and files — before it reaches the LLM, achieving 60–95% fewer tokens with the same answers.

View details
84
Repo Health
86
Technical
73
Dependency
Built with
Python80%
Rust14%
Updated today
Python
61%
Apache 2.0

marimo

Developer Tools · Data Engineering

22,393

A reactive Python notebook that eliminates hidden state, runs reproducibly, and deploys as a web app or script — stored as pure Python, built for the AI era.

View details
90
Repo Health
91
Technical
66
Dependency
Built with
Python61%
TypeScript37%
Updated today
Go
56%
Apache 2.0

OSV.dev

Security

2,888

Google's open-source vulnerability database that maps CVEs to exact package versions across 50+ ecosystems with a public API and data dumps.

View details
90
Repo Health
82
Technical
70
Dependency
Built with
Go56%
Python32%
Updated today
Python
94%
Apache 2.0

SWIRL

Search · Databases · Data Engineering

3,039

Federated AI search and RAG across 100+ enterprise sources—no data extraction, no vector database required.

View details
77
Repo Health
83
Technical
65
Dependency
Built with
Python94%
Updated 2 days ago
Python
91%
GPL 3.0

Weblate

Developer Tools

6,028

Continuous localization platform that commits translations directly into your version control system with full translator attribution.

View details
95
Repo Health
86
Technical
74
Dependency
Built with
Python91%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search