tomlclass
Lossless TOML editing and typed configuration in one zero-dependency package.
Change one value in a config file without breaking a single comment; declare schemas as Python classes to get commented templates, aggregated validation and diff-based write-back.
Features
- Lossless editing engine: full-type TOML 1.0/1.1 parse and write-back; all 709 toml-test 1.0 cases pass. Untouched documents render byte-identical to input
- One-line updates:
tomlclass.update("app.toml", {"server.port": 9090})— read, change, atomically write back; comments, ordering and formatting survive everywhere else - Typed config: declare the schema as classes — docstrings become template comments, validation aggregates all errors with each field's documented intent, defaults are merged in memory and never written back
- Comment operations: read, replace and delete comments per key; schema descriptions can be injected as comments (three strategies)
- tomllib compatible:
loads/loadfollow the stdlib calling convention — migrating costs nothing
Why not tomlkit
tomlkit is the de facto standard for lossless editing, and this project's engine was built against it as a baseline. Where tomlclass wins:
| Dimension | tomlkit 0.15 | tomlclass 0.1 |
|---|---|---|
| Parse speed (same machine) | baseline | 5.8–6.4× faster |
| Getting a plain dict | parse(dumps(doc)) round trip |
to_dict() builds it directly, zero round trip |
| Comment operations | buried in style objects, no per-key API | doc.comment(key) / set_comment as first-class citizens |
| Schema / template / validation | none — assemble it yourself | built into Config (template, aggregate validation, env overrides, migration) |
| Resident memory | baseline | 0.67× |
Source: performance baseline (same machine, same iteration count).
Installation
pip install tomlclass
Usage
Change one value, keep everything else
import tomlclass
tomlclass.update("pyproject.toml", {"project.version": "1.0.0"})
# only that line changed — comments, ordering and formatting all intact
Editing a TOML file (full control)
import tomlclass
doc = tomlclass.parse(text)
doc["project"]["version"] = "1.0.0"
doc["project"]["dependencies"].append("rich>=13.0") # spliced in place, comments kept
text = doc.dumps() # only touched lines change
Declarative config
from tomlclass import Config
class Server(Config):
"""
HTTP server settings.
host:
Address to bind.
port:
Port to listen on.
"""
host: str = "127.0.0.1"
port: int = 8000
server = Server.load("server.toml") # read + validate + merge defaults
server.port = 9000
server.save("server.toml") # only changed keys are written
Documentation
- Engine — parse, edit,
update(), comment API, errors - Config — schema declaration, template, load/save semantics, validation errors
- Comments — comment ownership, injection modes
- Examples — end-to-end scenarios
- Performance — measured baseline
Docs are also available in 简体中文, 繁體中文, 日本語 and Русский.
Requirements
Python ≥ 3.10, no third-party dependencies.
License
Metadata
Release files for tomlclass 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tomlclass-0.1.3.tar.gz | 264.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tomlclass-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 297.2 kB
Release files / tomlclass-0.1.3.tar.gz
| Download URL | tomlclass-0.1.3.tar.gz |
|---|---|
| Size | 264.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ed8d6d19caa2bfbbc7517e57cf935eecd223f3b639b0ba4320ef3b98a67c21b7
|
|
BLAKE2b-256 checksum How to use checksums |
f609a03d20983f36f9fac59be827154fd4285d812e7cbbef9796d301505c1f2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.
Transparency logRelease files / tomlclass-0.1.3-py3-none-any.whl
| Download URL | tomlclass-0.1.3-py3-none-any.whl |
|---|---|
| Size | 33.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6e30615b2e4c2ce628af4c040bef412690d4b782027488bd12921eeb83e0a9d9
|
|
BLAKE2b-256 checksum How to use checksums |
3f5945d210445c64b1a31630cce56608753a084feb0236c3611e73e72cc46516
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.
Transparency log