16.1. TOML

16.1.1. SetUp

>>> import tomllib

16.1.2. From String

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

16.1.3. From File

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

16.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

16.1.5. Example

[project]
name = "myproject"
version = "1.0.0"
requires-python = ">=3.13"
authors = [{name = "Mark Watney", email = "mwatney@nasa.gov"}]
readme = "README.md"
license = {file = "LICENSE"}
keywords = ["ares", "mars", "nasa", "human-spaceflight"]
dependencies = [
    "django == 5.1.*",
    "django-ninja == 1.3.*"]