toml

Read and write TOML, the config-file format used by tb.toml and pyproject.toml: toml.parse(text) gives a map (tables become maps, dates become ISO text), toml.stringify(map) writes one back, toml.read/write work on files.

import toml

Example

import toml

let config = toml.parse("title = \"triage\"\n[alerts]\nlevel = \"high\"\nports = [22, 3389]\n")
say(config.title, config.alerts.level, config.alerts.ports)
say(toml.stringify({"owner": {"name": "Tanisha"}, "debug": false}))

Functions

parse(text)

returns map

Read TOML text: tables [a.b] become nested maps, [[items]] become lists of maps, dates and times become ISO text like "2026-10-26T09:00:00".

Visualizehow toml.parse works

toml.parse("title = \"TB\"\n[server]\nport = 8080\ntls = true") gives {"title": "TB", "server": {"port": 8080, "tls": true}}

toml.parse: inputs flowing into the function and the resulttexttitle = "TB"[server]port = 8080tls = truetoml.parse[server] becomes a nested maptitle"TB"server{map}port8080tlstrue

Real result: worked out by running this example with TB while the site was built.

stringify(map)

returns text

Write a map as TOML: plain values first, then [tables] for nested maps and [[tables]] for lists of maps. nil can't be written (TOML has no nil), so leave such keys out.

Visualizehow toml.stringify works

toml.stringify({"title": "TB", "server": {"port": 8080, "tls": true}}) gives "title = \"TB\"\n\n[server]\nport = 8080\ntls = true\n"

toml.stringify: inputs flowing into the function and the resultmaptitle"TB"server{map}port8080tlstruetoml.stringifyplain values first, then [tables]title = "TB" [server]port = 8080tls = true

Real result: worked out by running this example with TB while the site was built.

read(path)

returns map

Read a TOML file (see parse).

Visualizehow toml.read works

toml.read("config.toml") gives {"title": "TB", "server": {"port": 8080}}

toml.read: inputs flowing into the function and the resultpath"config.toml"config.tomltitle = "TB"[server]port = 8080toml.reada TB maptitle"TB"server{map}port8080

Real result: worked out by running this example with TB while the site was built.

write(path, map)

Save a map as a TOML file (see stringify).

Visualizehow toml.write works

toml.write("app.toml", {"name": "notes", "window": {"width": 640, "height": 480}})

toml.write: inputs flowing into the function and the resultpath"app.toml"mapname"notes"window{map}width640height480toml.writeapp.toml afterwards (read back)name = "notes" [window]width = 640height = 480

Real result: worked out by running this example with TB while the site was built.

Values

NameValueWhat it is
toml.nativetrue

True when Python's own tomllib does the parsing (3.11+); false means TB's small built-in parser.

Visualizehow toml.native works

toml.native gives true

The value toml.nativetoml.nativetruewhat it isTrue when Python's own tomllib does theparsing (3.11+); false means TB's smallbuilt-in parser.

No inputs: call it as it is.

Real value, read from TB while the site was built.