Skip to main content

tomlclass

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.

Versioning: tomlclass is pre-1.0 and does not strictly follow SemVer yet. Before the project stabilizes, minor version bumps may include new API additions — existing APIs will remain backward compatible.

PyPI Python CI License Ruff



Features

  • Lossless editing engine: TOML 1.0/1.1 parse and write-back; the only library with a perfect 187/187 on toml-test 1.5.0 valid tests. Untouched documents render byte-identical to input
  • TOML 1.1 with a version dial: \e / \x escapes, seconds-optional times, newlines and trailing commas in inline tables, non-ASCII bare keys — on by default; pass toml_version="1.0" to parse / loads / load / update / Config.load for strict legacy rejection semantics
  • None your way: opt-in rtoml-style none_value sentinel — dumps(data, none_value="@None") and loads(text, none_value="@None") round-trip None through TOML strings
  • 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 / load follow the stdlib calling convention — migrating costs nothing

TOML version boundary: the 1.1 additions above are accepted by default. If your code relies on rejecting 1.0-invalid input (e.g. 13:37 times), switch to toml_version="1.0" — the same files then raise TOMLParseError.

Conformance & performance

Measured with toml-bench (toml-test 1.5.0 + CPython tomllib test data; speed = load/dump over 5000 iterations on one machine, tomlclass 0.2.0 — methodology in the benchmark baseline):

Check tomlclass 0.2.0
toml-test 1.5.0 valid (187 files) 187/187 — the only library with a perfect score
toml-test 1.5.0 TOML-1.1 manifest (548 files) 548/548
CPython tomllib test data 12/12 valid, 50/50 invalid

Speed (load / dump, 5000 iterations):

Library rtoml corpus tomli corpus
rtoml 0.11 (Rust) 0.72s / 0.16s 0.52s / 0.33s
tomli 2.4 + tomli_w 1.52s / 1.17s 1.26s / 0.84s
tomllib (CPython) 3.39s / — 2.15s / —
tomlclass 0.2.0 4.26s / 3.80s 3.12s / 2.22s
qtoml 0.3 7.78s / 2.97s 6.35s / 1.97s
tomlkit 0.15 60.45s / 1.75s 36.88s / 0.81s

Lossless editing pays for bookkeeping: loads run ~2.5–2.8× tomli, dumps ~2.6–3.2× tomli_w — and 12–14× faster than tomlkit.

Installation## 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

MIT

Metadata

Release files for tomlclass 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tomlclass 0.2.0
File Size Uploaded
tomlclass-0.2.0.tar.gz 270.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tomlclass 0.2.0
File Interpreter ABI Platform
tomlclass-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 305.3 kB

Release files / tomlclass-0.2.0.tar.gz

Download URL tomlclass-0.2.0.tar.gz
Size 270.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8296128f2a4497ccfef23ddb355de7ea35466a0819b418de40909125dacbb4da
BLAKE2b-256 checksum
How to use checksums
59707ebafd63b6a6ce6c7c37e5e9482d1bd11c0068f884864563a89845621600
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

Release files / tomlclass-0.2.0-py3-none-any.whl

Download URL tomlclass-0.2.0-py3-none-any.whl
Size 34.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
074c904767aa00c9f9228e46800d961964cbf05f3887d0f2eb2acd0ff994683d
BLAKE2b-256 checksum
How to use checksums
7a4b085e1317b04be71457fd04a2552ea33be851be5e321ae23720d74f6ad54c
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

Release history Release notifications | RSS feed

0.2.1

2 release files

This release

0.2.0 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page