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 mapRead 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}}
Real result: worked out by running this example with TB while the site was built.
stringify(map)
returns textWrite 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"
Real result: worked out by running this example with TB while the site was built.
read(path)
returns mapRead a TOML file (see parse).
Visualizehow toml.read works
toml.read("config.toml") gives {"title": "TB", "server": {"port": 8080}}
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}})
Real result: worked out by running this example with TB while the site was built.
Values
| Name | Value | What it is |
|---|---|---|
toml.native | true | True when Python's own tomllib does the parsing (3.11+); false means TB's small built-in parser. Visualizehow toml.native works
No inputs: call it as it is. Real value, read from TB while the site was built. |