Python 3.11 Preview: TOML and tomllib

Python 3.11 Preview: TOML and tomllib

by Geir Arne Hjelle Updated Reading time estimate 35m intermediate data-structures python

Python 3.11 is getting closer to its final release, which will happen in October 2022. The new version is currently going through beta testing, and you can install it yourself to preview and test some of the new features, including support for reading TOML with the new tomllib module.

TOML is a configuration file format that’s getting more and more popular in the Python ecosystem. This is driven by the adoption of pyproject.toml as the central configuration file in Python packaging. Other important tools, like Black, mypy, and pytest, also use TOML for their configuration.

In this tutorial, you’ll:

  • Install Python 3.11 beta on your computer, next to your current Python installations
  • Get familiar with the basics of the TOML format
  • Read TOML files with the new tomllib module
  • Write TOML with third-party libraries and learn why this functionality is not included in tomllib
  • Explore Python 3.11’s new typing features, including the Self and LiteralString types as well as variadic generics

There are many other new features and improvements coming in Python 3.11. Check out what’s new in the changelog for an up-to-date list, and read other Python 3.11 previews on Real Python to learn about other features.

Python 3.11 Beta

A new version of Python is released in October each year. The code is developed and tested over a seventeen-month period before the release date. New features are implemented during the