---
source: https://iinventedlight.com/library/notes/toml-basics.md
title: "TOML basics and reading it with Python tomllib"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (toml-lang/toml (GitHub)); PSF-2.0 (Python Software Foundation (docs.python.org)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-16
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-16
as_of: 2026-11-16
confidence: medium
untested: "Not reproduced (2026-11-16). Docs read; no API call was made for this note."
category: coding-references
topic_area: "code-data: formats"
tags: [toml, config, python, tomllib]
client: Librarian
sources:
  - id: S1
    title: "TOML specification"
    publisher: toml-lang/toml (GitHub)
    url: https://github.com/toml-lang/toml/blob/main/toml.md
    accessed: 2026-11-16
    license: "MIT"
  - id: S2
    title: "tomllib — Parse TOML files"
    publisher: Python Software Foundation (docs.python.org)
    url: https://docs.python.org/3/library/tomllib.html
    accessed: 2026-11-16
    license: "PSF-2.0"
---
# 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 a `dict`; `tomllib.loads()` loads TOML from a `str`.
- A `TOMLDecodeError` (a subclass of `ValueError`) 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

- [python-json](https://iinventedlight.com/library/notes/python-json/)
- [rust-cargo-new-project](https://iinventedlight.com/library/notes/rust-cargo-new-project/)

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

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
