Python's Built-in tomllib Module — ELI5

Imagine you move into a new apartment. The kitchen has a stove, a fridge, and a sink — but no can opener. Every time you want to open a can of beans, you need to go buy a separate tool. Annoying, right?

For years, Python had this problem with TOML files. TOML is a popular format for configuration files — it’s where Python projects store their settings in a file called pyproject.toml. But Python itself couldn’t read TOML files. You had to install a separate package first.

Starting with Python 3.11, the tomllib module is built right in. It’s like the apartment finally comes with a can opener in the drawer. You just open it and use it — no extra shopping required.

TOML files look like this:

[project]
name = "my-app"
version = "1.0"

[database]
host = "localhost"
port = 5432

They’re designed to be easy for humans to read and write. Unlike JSON, they support comments. Unlike YAML, they don’t have confusing indentation rules that can cause bugs.

With tomllib, you write two lines of Python code and your config is loaded into a regular dictionary. No install step, no version conflicts, no dependency headaches.

The module only reads TOML — it can’t write it. That might seem limiting, but reading config files is the common case. If you need to generate TOML, there are still third-party packages for that.

The one thing to remember: tomllib is Python’s built-in TOML reader — no install needed, just import it and read your config files directly.

pythonstdlibpython311

See Also

  • Python Atexit How Python's atexit module lets your program clean up after itself right before it shuts down.
  • Python Bisect Sorted Lists How Python's bisect module finds things in sorted lists the way you'd find a word in a dictionary — by jumping to the middle.
  • Python Contextlib How Python's contextlib module makes the 'with' statement work for anything, not just files.
  • Python Copy Module Why copying data in Python isn't as simple as it sounds, and how the copy module prevents sneaky bugs.
  • Python Dataclass Field Metadata How Python dataclass fields can carry hidden notes — like sticky notes on a filing cabinet that tools read automatically.