8.1. TOML

8.1.1. SetUp

>>> import tomllib

8.1.2. From String

>>> toml_str = """
... python-version = "3.11.3"
... python-implementation = "CPython"
... """
>>>
>>> data = tomllib.loads(toml_str)
>>> data
{'python-version': '3.11.3', 'python-implementation': 'CPython'}

8.1.3. From File

>>> with open('pyproject.toml', 'rb') as f:  
...     data = tomllib.load(f)

8.1.4. Conversion Table

TOML

Python

table

dict

string

str

integer

int

float

float (configurable with parse_float)

boolean

bool

offset date-time

datetime.datetime (tzinfo attribute set to an instance of datetime.timezone)

local date-time

datetime.datetime (tzinfo attribute set to None)

local date

datetime.date

local time

datetime.time

array

list