Cheat Sheets Development

TOML Syntax Cheat Sheet

Every TOML value type, tables, arrays of tables, dotted keys, strings and dates on one page, with a complete example that was parsed with Python 3.12's tomllib.

Last reviewed:

AdSense Placeholder
Slot: header_reference_page
On this page

TOML (Tom's Obvious Minimal Language) is a configuration format designed to be unambiguous to read and to map onto a hash table. It is used by pyproject.toml, Cargo.toml and many tools. Convert between formats with the TOML to JSON Converter and the JSON to TOML Converter.

A complete example

# A comment
title = "Example"
count = 42
ratio = 3.14
enabled = true
released = 2026-10-28
updated = 2026-10-28T07:32:00Z
tags = ["a", "b", "c"]
products = [
  { name = "Hammer", sku = 738594937 },
  { name = "Nail", sku = 284758393 },
]

[server]
host = "localhost"
port = 8080

[server.tls]
enabled = false

Value types

Type Examples
String "basic" (escapes allowed), 'literal' (no escapes), """multi-line""", '''multi-line literal'''
Integer 42, +17, -5, 1_000, 0xFF, 0o17, 0b101
Float 3.14, -0.01, 6.626e-34, +inf, -inf, nan
Boolean true, false (lowercase only)
Offset date-time 2026-10-28T07:32:00Z or 2026-10-28T07:32:00+02:00
Local date-time 2026-10-28T07:32:00 (no zone)
Local date 2026-10-28
Local time 07:32:00
Array [1, 2, 3], may span lines and have a trailing comma
Inline table { a = 1, b = 2 } (one line)

Tables, dotted keys and arrays of tables

  • A [table] header starts a section; every key below it belongs to that table until the next header.
  • [a.b] defines table b inside a. The same key path can only be defined once.
  • Dotted keys such as a.b.c = 1 create nested tables without headers: the result is {"a": {"b": {"c": 1}}}.
  • A header with the name wrapped in doubled square brackets (two opening brackets, the name, two closing brackets, no spaces) appends a new table to an array of tables. Each repeated header adds one element; an array of inline tables, as in the example, does the same on one line.

Rules that trip people up

  • Keys are case-sensitive and unquoted keys may only use A-Za-z0-9_-. Quote anything else: "my key" = 1.
  • A key cannot be defined twice, and [server] after server.port = 1 is an error.
  • Integers have no leading zeros (007 is invalid) and floats need digits on both sides of the dot (.5 and 5. are invalid).
  • There is no null. Leave the key out, or use an empty string or a documented sentinel.
  • Arrays may mix types in TOML 1.0, but most tools expect one type.
  • Whitespace is not significant, unlike YAML, but a value must end its line.

Try these tools

See also

  • Cheat sheet YAML Syntax Cheat Sheet
    Quick reference for YAML: scalars, strings, lists, mappings, multi-line text, anchors.
  • Comparison TOML vs YAML vs JSON
    Three configuration formats compared: comments, readability, data types, pitfalls and typical uses.
  • Glossary TOML
    TOML is a small configuration file format with clear types and sections.
  • Glossary YAML
    YAML is a human-friendly data format that uses indentation instead of brackets, popular for configuration files.
AdSense Placeholder
Slot: footer_leaderboard