Hands-on tomllib vs json.load nested config lab: real loads/s (stdlib TOML read-only), measured on Linux localhost today in this hands-on lab for SREs.
4 min read
Load equivalent nested app config from TOML via tomllib vs JSON via json. This lab reports loads/s on Linux localhost.
Stdlib tomllib is read-only (no dumps). It is not configparser-vs-json (lab 104) and not json dumps compact/indent (lab 75).
Related links:
Lab honesty (1 Oct 2026 IST): Python 3.13.5. Affiliates: 0. Same logical tables/objects in .toml and .json.
Verdict up front (medium ≈ 22 sections / 306 keys, TOML 5260 B / JSON 5917 B): json.loads ~31027.0 loads/s; json.load file ~22155.3; tomllib.loads ~1054.1; tomllib.load file ~1021.4.
| Arm | API |
|---|---|
tomllib.load(binary_file) | stdlib TOML file |
tomllib.loads(str) | TOML string |
json.load / json.loads | JSON file/string |
json.loads on indented | whitespace sensitivity |
Script: lab-evidence/112-tomllib-vs-json/results/run_lab.py.
| Arm | loads/s |
|---|---|
| json.loads | 31027.0 |
| json.loads (indent=2 text) | 29808.0 |
| json.load file | 22155.3 |
| tomllib.loads | 1054.1 |
| tomllib.load file | 1021.4 |
JSON file load is roughly ~22× tomllib here.
| Size | tomllib.load | json.load |
|---|---|---|
| small | 6818.7 | 58524.0 |
| medium | 1021.4 | 22155.3 |
| large | 160.4 | 4290.0 |
pyproject.toml style); stdlib can only read.json.dumps; no comments.tomllib.Teams often prototype in TOML then discover they need to serialize overrides at runtime. Budget a writer library early, or keep JSON/YAML for generated overlays while humans still edit a TOML base — this lab only measures load.
configparser (lab 104) or dumps formatting (lab 75)."rb") for tomllib.load.TOML preserves richer literal types (booleans/ints without quotes in our fixture) and allows # comments in real files — JSON does not. That ergonomics win is why pyproject.toml exists even when JSON parses faster on this box. If your config is generated and consumed only by machines, JSON’s speed and dumps symmetry usually win.
Lab 104 compared INI/configparser to JSON. TOML sits closer to JSON’s nested data model while staying human-editable. Do not treat tomllib numbers as interchangeable with configparser numbers — different parsers, different fixtures, different features (interpolation, etc.).
tomllib.load requires a binary file object. Passing open(path, "r") raises. Prefer Path.open("rb") or tomllib.loads(path.read_text()) when you already have str text (slightly different decode path — both measured).
tomllib.dumps in stdlib (it does not exist).tomllib.load.Evidence: summary.json, summary.txt, fixtures/.
Cold-start services that parse config once can ignore the loads/s gap; hot reloaders and per-request overlays should prefer JSON or a cached dict.
One Linux box. Synthetic nested tables. Not TOML datetime/array-of-tables stress. Not orjson.
On medium nested config, json.load ~22155.3 loads/s beat tomllib.load ~1021.4 loads/s. Pick TOML for editable configs (read-only stdlib), JSON for speed/write path.
Lab evidence
Lab 1 Oct 2026 IST. Python 3.13.5. medium: json_load_file 22155.3 loads/s; tomllib_load_file 1021.4; json_loads 31027.0. tomllib read-only. Not lab 104/75. Affiliates: 0. Evidence: lab-evidence/112-tomllib-vs-json/.
A hands-on localhost lab comparing configparser and json.load for nested application configuration.
Lab1 Oct 20264 min read
Hands-on platform.platform vs os.uname host inventory lab: real ops/s plus cache notes, measured on Linux localhost today in this hands-on lab for SREs.
Summary1 Oct 20264 min read
Hands-on uuid.uuid4 vs uuid.uuid1 ID generation lab: real ops/s plus version/node checks, measured on Linux localhost today in this hands-on lab for SREs.
Summary1 Oct 20263 min read