Syntax
tomllib.loads(text); tomllib.load(binary_file)Examples
Reading TOML Configuration
Run as a Python 3.11+ script.
import tomllib
config = tomllib.loads('[server]\nport = 8080\nenabled = true\n')
print(config["server"]["port"] + 1)
print(config["server"]["enabled"])- Expected output: 8081 True
- The parser produces an integer and a boolean directly. Real files passed to load must be opened in binary mode.
Best practices
- Validate required keys and application-specific ranges after parsing.
- Use a dedicated TOML writer if configuration must be edited.
Runtime & versions
Python interpreter. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
Python language reference