On this page
tomllib.load
Up: tomllib | Next: tomllib.loads
Rel: tomllib.loads, tomllib.TOMLDecodeError
Ref: docs.python.org — tomllib.load
Tags: #public #python3 #stdlib #tomllib
Import
import tomllib
from tomllib import load
Signature & Overview
tomllib.load(fp: 'IO[bytes]', /, *, parse_float: 'ParseFloat' = <class 'float'>) -> 'dict[str, Any]'
Parse TOML from a binary file object.
Usage
import io
import tomllib
raw = io.BytesIO(b'[project]\nname = "demo"\nversion = "0.1.0"\n')
data = tomllib.load(raw)
assert data["project"]["name"] == "demo"
Gotchas
- Requires binary mode (
"rb"): Unlikejson.load(), passing a text file opened in"r"mode raisesTypeError—always useopen("pyproject.toml", "rb"). - Read-only module:
tomllibdoes not write TOML; usetomli_wortomlkitto serialize TOML.
REPL Inspect
from tomllib import load
help(load)
Linked from
Related notes
- tuts/python3/stdlib_module/tomllib/loads Linked here; links to this page; shared tags: #stdlib, #tomllib
- tuts/python3/stdlib_module/tomllib/TOMLDecodeError Linked here; links to this page; shared tags: #stdlib, #tomllib
- tuts/python3/stdlib_module/tomllib Linked here; links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib
- tuts/c/stdlib/ctype/isalpha shared tags: #stdlib
- tuts/c/stdlib/ctype/isdigit shared tags: #stdlib