toml.encoder
import toml.encoder
tomldoes not re-export this module, so it is reached only by importing it directly.
Turning a plain Zuri value into a document.
The parser’s job is to lose nothing. This one’s is the opposite: there
is no original text to preserve, so every choice has to be made from
scratch. Which dictionaries become [table] blocks and which become
inline tables, which lists become [[array of table]] blocks, where a
long array breaks across lines, whether a string with a newline in it is
escaped or written out in triple quotes.
Every one of those is an option with a stated default, and the result is
a Document like any other, so a freshly encoded value and a parsed
file are the same kind of thing afterwards.
Functions
encode()
toml.encoder.encode(value, options) -> Document
Builds the document for a Zuri dictionary.
A TOML file is a table, so the value has to be a dictionary. Everything
under it is placed by what it is: a dictionary becomes a [table]
block, a non-empty list of dictionaries becomes a [[array of tables]],
and everything else becomes a pair on a line.
Parameters
value(dict) — The value to write.options(?dict) —sort_keys(defaultfalse) writes keys in sorted order instead of insertion order.inline_threshold(default0, off) writes a flat table inline when its inline form is no longer than this many characters.multiline_strings(defaulttrue) writes a string holding a newline in triple quotes rather than escaping it.array_width(default80) is the length past which an array breaks onto one line per item.
Returns Document
Raises EncodeError If the value is not a dictionary, holds a nil
or a value with no TOML spelling, has a non-string key, or contains
itself.
2026, Richard Ore and The Zuri Contributors