Configuration & Data Formats

toml

A config file format one GitHub co-founder built because YAML's quirks were driving him up the wall.

Install it: pip install toml

What does it do?

This library reads and writes TOML files, a configuration format built around simple key-value pairs that look almost like a shopping list: name equals value, one line at a time, grouped into clearly labeled sections. Where YAML relies on careful indentation that can silently break if a single space is off, TOML aims to be nearly impossible to get wrong, more like filling out a straightforward form than writing code. The Python toml library lets a program read one of these files into ordinary Python data and write Python data back out as a tidy TOML file. It’s deliberately unambitious, doing one small job predictably.

See it in action

This reads a project’s name out of an existing settings file, then writes a brand new settings file containing a couple of simple options.

import toml

config = toml.load("pyproject.toml")
print(config["project"]["name"])

with open("settings.toml", "w") as f:
    toml.dump({"debug": True, "port": 8080}, f)

Why would a non-developer care?

You’ve likely never had to write TOML yourself, but if you’ve installed a modern Python tool, there’s a good chance it kept its own settings in a file named pyproject.toml, and that predictability is exactly why the Python community adopted it as a standard.

Real-world examples

TOML was created by Tom Preston-Werner, a co-founder of GitHub, specifically because he wanted a config format simpler and less surprising than YAML or JSON for humans to edit by hand. Python’s own packaging tools now standardize on pyproject.toml for describing a project’s dependencies and build settings, meaning this small library sits underneath a huge share of the modern Python toolchain.

Who uses it

Python package maintainers and tool authors who need a config file format that’s hard to write incorrectly.

How it compares to alternatives

Against YAML, TOML trades some flexibility for far fewer surprises, no ambiguous indentation, no accidental type conversions. Against plain JSON, it’s much friendlier for a human to type and edit directly, since JSON was really designed for machines to exchange data.

Fun fact

TOML’s name is a deliberate acronym for “Tom’s Obvious, Minimal Language,” named directly after its creator, a rare case of a file format openly bearing its inventor’s name.

New to Python and want to actually try libraries like this yourself?

Find a beginner-friendly course

Related libraries