3. Use tomllib for reading TOML
Use the standard-library tomllib module for read-only TOML parsing.
Using the standard library removes an extra dependency for a very common configuration format and makes the parsing expectations obvious to readers. It is a strong default when you only need to read TOML, which is the common case for files like pyproject.toml.
Note
Python 3.11+
3.1. Don’t do this
1import toml
2
3with open('pyproject.toml', 'rb') as f:
4 data = toml.load(f)
3.2. Do this
1import tomllib
2
3with open('pyproject.toml', 'rb') as f:
4 data = tomllib.load(f)