Tomli
Tomli is a Python library for parsing TOML (Tom's Obvious, Minimal Language) files, fully compatible with TOML v1.0.0. As of version 2.4.1, it provides a backport of the standard library's `tomllib` module introduced in Python 3.11, ensuring compatibility for earlier Python versions. The library is actively maintained, with regular updates to enhance functionality and maintain compatibility.
Warnings
- breaking Tomli is read-only; it does not support writing TOML files.
- gotcha Tomli requires file objects to be opened in binary mode ('rb').
- gotcha Tomli does not preserve comments or formatting in TOML files.
Install
-
pip install tomli
Imports
- load
from tomli import load
- loads
from tomli import loads
Quickstart
import tomli
with open('config.toml', 'rb') as f:
config = tomli.load(f)
print(config)