TOML Cheatsheet

Keys, values, tables, arrays & common config patterns

Data Format
Contents
📝

Basics

# TOML = Tom's Obvious Minimal Language
# Designed for config files

# Key-value pairs
name = "Alice"
age = 30
active = true

# Comments with #
# Keys are bare or quoted
bare-key = "value"
"quoted key" = "value"
"key.with.dots" = "value"

# Dotted keys (creates nested tables)
server.host = "localhost"
server.port = 8080
💎

Data Types

# String
str1 = "basic string"
str2 = 'literal string (no escapes)'
str3 = """
multi-line
basic string"""
str4 = '''
multi-line
literal string'''

# Integer
int1 = 42
int2 = 1_000_000          # underscore separator
hex = 0xDEADBEEF
oct = 0o755
bin = 0b11010110

# Float
flt1 = 3.14
flt2 = 1e6
special1 = inf
special2 = nan

# Boolean
enabled = true
disabled = false
📦

Tables

# Table (like object/dict)
[server]
host = "localhost"
port = 8080

# Nested table
[database]
host = "localhost"
port = 5432

[database.connection]
pool_size = 10
timeout = 30

# Super-table (dotted)
[a.b.c]
key = "value"
# Same as: a → b → c → key
📋

Arrays

# Array
colors = ["red", "green", "blue"]
numbers = [1, 2, 3]
nested = [[1, 2], [3, 4]]

# Multi-line array
hosts = [
    "alpha",
    "beta",
    "gamma",   # trailing comma OK
]

# Array of tables
[[products]]
name = "Hammer"
price = 9.99

[[products]]
name = "Nail"
price = 0.05
# → products = [{name: "Hammer"...}, {name: "Nail"...}]
🔧

Inline Tables

# Inline table (single line)
point = { x = 1, y = 2 }
user = { name = "Alice", age = 30 }

# Inline array of inline tables
points = [
    { x = 0, y = 0 },
    { x = 1, y = 1 },
]
📅

Dates & Times

# Offset date-time
odt = 2024-01-15T10:30:00Z
odt2 = 2024-01-15T10:30:00-05:00

# Local date-time
ldt = 2024-01-15T10:30:00

# Local date
ld = 2024-01-15

# Local time
lt = 10:30:00
📋

Common Patterns

# Cargo.toml (Rust)
[package]
name = "my-app"
version = "0.1.0"
edition = "2021"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1", features = ["full"] }

# pyproject.toml (Python)
[project]
name = "my-app"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["fastapi", "uvicorn"]

[tool.ruff]
line-length = 88