Read TOML file in Python
Read TOML file in Python
March 21, 2024
Use pathlib to read and tomllib to parse the file. (requires Python >= 3.11)
For example, to extract Julia version from Manifest.toml,
import tomllib; from pathlib import Path; print(tomllib.loads(Path("Manifest.toml").read_text())["julia_version"])And it’s easy to run in a bash shell or CI script.
python -c 'import tomllib; from pathlib import Path; print(tomllib.loads(Path("Manifest.toml").read_text())["julia_version"])'Last updated on