TOML basics and reading it with Python tomllib
Answer: TOML aims to be a minimal, easy-to-read configuration format with obvious semantics. It is designed to map unambiguously to a hash table.
Rules
- TOML is case-sensitive, and a TOML file must be a valid UTF-8 encoded Unicode document.
- A
[table]header starts a table; key/value pairs follow until the next header or EOF, and are not guaranteed to be in any specific order. - Inline tables, fully defined within curly braces, are a compact syntax for grouped nested data.
- Value types include strings, integers, floats, booleans, offset date-times, local dates and times, arrays and tables.
Python
tomllib.load()reads a TOML file from a readable and binary file object and returns adict;tomllib.loads()loads TOML from astr.- A
TOMLDecodeError(a subclass ofValueError) is raised on an invalid TOML document. - This module does not support writing TOML. It was added in Python 3.11 with support for TOML 1.0.0.
See also
Claims
- id: C1 claim: TOML is minimal and maps to a hash table. source: S1 evidence: "TOML is designed to map unambiguously to a hash table."
- id: C2 claim: TOML files must be UTF-8. source: S1 evidence: "A TOML file must be a valid UTF-8 encoded Unicode document."
- id: C3 claim: tomllib cannot write TOML. source: S2 evidence: "This module does not support writing TOML."
Sources
- [S1] TOML specification. toml-lang/toml (GitHub). https://github.com/toml-lang/toml/blob/main/toml.md . License: MIT. Accessed 2026-11-16.
- [S2] tomllib — Parse TOML files. Python Software Foundation (docs.python.org). https://docs.python.org/3/library/tomllib.html . License: PSF-2.0. Accessed 2026-11-16.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: toml-lang/toml (GitHub), TOML specification, MIT (https://raw.githubusercontent.com/toml-lang/toml/main/LICENSE). Copyright (c) Tom Preston-Werner; Python Software Foundation (docs.python.org), tomllib — Parse TOML files, PSF-2.0 (https://docs.python.org/3/library/tomllib.html (page footer: licensed under the Python Software Foundation License Version 2; code examples Zero Clause BSD)). Copyright 2001 Python Software Foundation. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: toml-lang/toml (GitHub), TOML specification, MIT (https://raw.githubusercontent.com/toml-lang/toml/main/LICENSE). Copyright (c) Tom Preston-Werner; Python Software Foundation (docs.python.org), tomllib — Parse TOML files, PSF-2.0 (https://docs.python.org/3/library/tomllib.html (page footer: licensed under the Python Software Foundation License Version 2; code examples Zero Clause BSD)). Copyright 2001 Python Software Foundation.
Cite this
iinventedlight. 2026. "TOML basics and reading it with Python tomllib." iinventedlight Library, iil:note:xpc9d0y6, version of 2026-11-16. https://iinventedlight.com/library/notes/toml-basics/. License: CC-BY-4.0.
@misc{iil_note_xpc9d0y6,
author = {{iinventedlight}},
title = {{TOML basics and reading it with Python tomllib}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-16},
url = {https://iinventedlight.com/library/notes/toml-basics/},
note = {Permanent ID iil:note:xpc9d0y6. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/toml-basics.md.