Formatcore
TOML
Also called Tom's Obvious, Minimal Language.
TOML is a text format for configuration files. A TOML document is one table of key and value pairs, with strings, integers, floats, booleans, four date and time types, arrays and nested tables.
What it is
TOML is a text format for configuration files. The name stands for "Tom's Obvious, Minimal Language". The specification gives three aims. TOML is a minimal configuration format that people can read because its semantics are obvious. It maps unambiguously to a hash table. Programs in many languages can parse it into data structures.2 A TOML document is one table. The table holds key and value pairs, and a value can be another table, so a document is a tree of tables.
A value has one of these types: string, integer, float, boolean, offset date-time, local date-time, local date, local time, array and inline table.2 There is no null. A key is always a string, even when it is written as digits.2 The top level is always a table. TOML cannot hold an array or a float at the top level, and it has no marker for the start or the end of a document. So the README of the project says that TOML is not for the serialization of arbitrary data.5
The README of the project compares TOML with JSON and YAML. TOML and JSON both use common data types that a machine can parse. TOML and YAML both have features for human readers, such as comments. TOML has comments, which JSON does not have, and it keeps a smaller grammar than YAML.5 In TOML, a string always has quotes, and the only booleans are true and false.2 PEP 518 chose TOML for the file pyproject.toml of Python projects. It compares TOML with YAML, JSON and other formats. It rejects YAML for two main reasons: the specification is large, and a tool that calls an unsafe load function can run arbitrary code.14 Cargo, the package manager of Rust, writes its manifest Cargo.toml in TOML.13
The file extension is .toml, and the media type is application/toml.2 IANA has the media type in its registry.6
History
Tom Preston-Werner wrote TOML. The byline of the specification names him, Pradyun Gedam and other authors.2 Version 0.1.0 came out on 17 March 2013. It was the first release, and it said that TOML follows SemVer for its version numbers.3 Version 0.2.0 (September 2013) renamed "key groups" to "tables" and added arrays of tables. Version 0.3.0 (November 2014) added multi-line and literal strings and moved datetimes to RFC 3339. Version 0.4.0 (February 2015) added inline tables and underscores in numbers. Version 0.5.0 (July 2018) added dotted keys, hexadecimal, octal and binary integers, inf and nan, the three local date and time types, and the ABNF grammar.3
Version 1.0.0 came out on 11 January 2021.3 PEP 680 took this release as the sign that the format is stable, and it added the read-only module tomllib to the Python standard library, based on the library tomli.8 Version 1.1.0 came out on 18 December 2025. It relaxed some rules and added some escapes (see Versions).3
Syntax or structure
The ABNF file of the project is the formal grammar, and the text of the specification adds the rules that the grammar cannot state, such as "a table is defined once".43 The excerpt below is from the file at the tag 1.1.0.4
toml = expression *( newline expression )
expression = ws [ comment ]
expression =/ ws keyval ws [ comment ]
expression =/ ws table ws [ comment ]
keyval = key keyval-sep val
key = simple-key / dotted-key
val = string / boolean / array / inline-table / date-time / float / integer
date-time = offset-date-time / local-date-time / local-date / local-time
partial-time = time-hour ":" time-minute [ ":" time-second [ time-secfrac ] ]
full-time = partial-time time-offset
offset-date-time = full-date time-delim full-time
local-date-time = full-date time-delim partial-time
table = std-table / array-table
std-table = std-table-open key std-table-close
array-table = array-table-open key array-table-close
A document is a sequence of lines. Each line is empty, a comment, a key and value pair, or a table header. A key, the equals sign and the value must be on the same line, though some values can continue over more lines.2 A document must be valid UTF-8. Version 1.1.0 says that a parser must reject a file that is not valid UTF-8, or replace the bad bytes with U+FFFD, and that rejection is preferred.2 A newline is LF or CRLF. Whitespace is tab or space, and TOML is case-sensitive.2
Comments. A # outside a string starts a comment to the end of the line. Version 1.1.0 says that a parser must not change keys or values because of a comment.2
Keys. A key is bare, quoted or dotted. A bare key has only the ASCII letters, the ASCII digits, _ and -. A quoted key follows the rules of a basic or a literal string. A dotted key is a sequence of bare or quoted keys joined by ., and it makes nested tables: physical.color = "orange" puts the key color in the table physical.2 Because a bare key can be all digits, 3.14159 = "pi" is a dotted key with the two parts 3 and 14159, not a float.2 A key defined twice is an error, and a bare key and a quoted key with the same text are the same key.2
Strings. There are four forms. A basic string is in double quotes and has escapes such as \n, \t, \", \\, \uXXXX and \UXXXXXXXX. A literal string is in single quotes and has no escapes, which suits Windows paths and regular expressions. Each form has a multi-line variant with three quotes. A newline directly after the opening delimiter is trimmed. In a multi-line basic string, a backslash at the end of a line removes the newline and the whitespace that follows it.2 An escape must be a Unicode scalar value, so a string cannot hold a lone surrogate. For binary data, the specification recommends an encoding such as Base64.2
Integers. An integer is decimal, with an optional sign and no leading zeros. A non-negative integer can also be hexadecimal (0x), octal (0o) or binary (0b). An underscore can go between two digits, as in 1_000.2 Version 1.0.0 says that a parser should accept every 64-bit signed integer, from -2^63 to 2^63-1, and must raise an error for an integer that it cannot hold without loss.1 Version 1.1.0 lets an implementation support any size, but keeps the recommendation and the error rule.2
Floats. A float has a fraction, an exponent or both, and the decimal point must have a digit on each side, so .7 and 7. are not valid. The special values are inf, +inf, -inf, nan, +nan and -nan, always in lowercase.2 Version 1.0.0 says floats should be IEEE 754 binary64 values.1
Booleans. The only booleans are true and false, in lowercase.2
Date and time. TOML has four types, based on RFC 3339. An offset date-time, such as 1979-05-27T07:32:00-07:00, is one instant. A local date-time, such as 1979-05-27T07:32:00, has no offset, and it cannot become an instant without more information. A local date is a whole day, and a local time is a time of day with no date. A space can replace the T. Implementations must support at least millisecond precision, and they truncate extra digits.2
Arrays. An array is a list of values in square brackets. The values can be of different types, and the array can span lines, with comments and a trailing comma.2
Tables. A header [name] on its own line starts a table. The keys under it, up to the next header or the end of the file, belong to it. The keys before the first header belong to the root table. A header can use a dotted name such as [servers.alpha], and TOML makes the parent tables that the name needs.2 A table can be defined only once. The key and value pairs of a table are not in a guaranteed order.2
Inline tables. The form point = { x = 1, y = 2 } defines a table inside a value. An inline table is complete: no key can be added to it later, from outside the braces.2
Arrays of tables. A header in double brackets, product, adds one more table to the array product each time it appears. A sub-table header such as [product.size] refers to the last table of the array.2
The rules for defining tables
Most errors in TOML files come from the rule that each table is defined once. The rule has several forms:2
- Two headers with the same name are an error.
- A header cannot name a table that dotted keys already defined. In
[fruit]withapple.color = "red", a later[fruit.apple]is an error. A header for a deeper table, such as[fruit.apple.texture], is allowed. - Dotted keys cannot add to a table that a header defined.
- Keys cannot be added to an inline table after it is closed, and an inline table cannot add keys to a table that exists.
fruitscannot append to an array that a key and value pair defined, such asfruits = [].- A header can define a parent table after its child, as
[x]after[x.y.z.w], because the child header only madeximplicitly.
Examples
The document below has each type of value. The Python module tomllib parses it into a dict. It maps an offset date-time to a datetime with a tzinfo, a local date-time to a datetime with no tzinfo, a local date to a date and a local time to a time.7
import tomllib
text = """
# A service configuration
name = "billing"
port = 8080
ratio = 0.25
debug = false
started = 2026-11-10T09:30:00+07:00
cutoff = 2026-11-10T17:00:00
holiday = 2026-12-25
backup = 02:30:00
hosts = ["alpha", "beta"]
[database]
url = 'postgres://db.local/billing'
pool.size = 10
[[worker]]
queue = "invoices"
[[worker]]
queue = "refunds"
"""
config = tomllib.loads(text)
for key, value in config.items():
print(f"{key:9} {type(value).__name__:9} {value!r}")
print(config["started"].utcoffset(), config["cutoff"].tzinfo)
name str 'billing'
port int 8080
ratio float 0.25
debug bool False
started datetime datetime.datetime(2026, 11, 10, 9, 30, tzinfo=datetime.timezone(datetime.timedelta(seconds=25200)))
cutoff datetime datetime.datetime(2026, 11, 10, 17, 0)
holiday date datetime.date(2026, 12, 25)
backup time datetime.time(2, 30)
hosts list ['alpha', 'beta']
database dict {'url': 'postgres://db.local/billing', 'pool': {'size': 10}}
worker list [{'queue': 'invoices'}, {'queue': 'refunds'}]
7:00:00 None
The rules for defining tables are the part of the format that a person breaks most often. Each document below breaks one rule, except the last, which adds a sub-table to a table that a header defined. The parser raises TOMLDecodeError with the line and the column.7
import tomllib
documents = {
"key twice": 'name = "a"\nname = "b"\n',
"table twice": "[fruit]\napple = 1\n[fruit]\npear = 2\n",
"dotted, then header": "[fruit]\napple.color = 'red'\n[fruit.apple]\nsize = 3\n",
"inline, then extend": "[product]\ntype = { name = 'Nail' }\ntype.edible = false\n",
"append to static array": "fruits = []\n[[fruits]]\n",
"header, then subtable": "[fruit]\napple = 1\n[fruit.pear]\nsize = 2\n",
}
for name, text in documents.items():
try:
tomllib.loads(text)
print(f"{name}: valid")
except tomllib.TOMLDecodeError as error:
print(f"{name}: {error}")
key twice: Cannot overwrite a value (at line 2, column 11)
table twice: Cannot declare ('fruit',) twice (at line 3, column 7)
dotted, then header: Cannot declare ('fruit', 'apple') twice (at line 3, column 13)
inline, then extend: Cannot mutate immutable namespace ('product', 'type') (at line 3, column 20)
append to static array: Cannot mutate immutable namespace ('fruits',) (at line 2, column 9)
header, then subtable: valid
A TOML float becomes a binary floating-point number by default, so 0.10 loses its decimal form. The argument parse_float gets the text of each float, and decimal.Decimal keeps it exact.7 Python integers have no fixed size, so tomllib keeps an integer above 2^63-1 without loss. A parser with 64-bit integers must reject the same document (see the Rust example).2
import tomllib
from decimal import Decimal
text = "price = 0.10\nlimit = 9223372036854775808\nmask = 0xFF_FF\nmissing = nan\n"
data = tomllib.loads(text)
print(data)
print(repr(tomllib.loads(text, parse_float=Decimal)["price"]))
{'price': 0.1, 'limit': 9223372036854775808, 'mask': 65535, 'missing': nan}
Decimal('0.10')
The example files show how Python, Rust and Java read and write TOML, how each one reports errors, and which writers keep the comments of a file.
import os
import tempfile
import tomllib
text = '[tool.example]\nname = "billing"\npaths = ["src", "tests"]\n'
folder = tempfile.mkdtemp()
path = os.path.join(folder, "pyproject.toml")
with open(path, "w", encoding="utf-8") as handle:
handle.write(text)
with open(path, "rb") as handle:
print(tomllib.load(handle))
try:
with open(path, encoding="utf-8") as handle:
tomllib.load(handle)
except TypeError as error:
print("TypeError:", error)
os.remove(path)
os.rmdir(folder)
{'tool': {'example': {'name': 'billing', 'paths': ['src', 'tests']}}}
TypeError: File must be opened in binary mode, e.g. use `open('foo.toml', 'rb')`
import tomllib
text = r'''
3.14159 = "pi"
"quoted key" = 1
site."google.com" = true
path = 'C:\Users\tam\config'
regex = '<\i\c*\s*>'
tab = "a\tb"
lines = """
first \
second"""
'''
for key, value in tomllib.loads(text).items():
print(repr(key), repr(value))
'3' {'14159': 'pi'}
'quoted key' 1
'site' {'google.com': True}
'path' 'C:\\Users\\tam\\config'
'regex' '<\\i\\c*\\s*>'
'tab' 'a\tb'
'lines' 'first second'
import json
import tomllib
name = "smile \U0001F600"
escaped = json.dumps(name)
print(escaped)
print(tomllib.loads(f"name = {json.dumps(name, ensure_ascii=False)}\n"))
try:
tomllib.loads(f"name = {escaped}\n")
except tomllib.TOMLDecodeError as error:
print("TOMLDecodeError:", error)
print(tomllib.loads('name = "smile \\U0001F600"\n'))
"smile \ud83d\ude00"
{'name': 'smile ๐'}
TOMLDecodeError: Escaped character is not a Unicode scalar value (at line 1, column 21)
{'name': 'smile ๐'}
import sys
import tomllib
documents = {
"multi-line inline table": "point = {\n x = 1,\n y = 2,\n}\n",
"time without seconds": "alarm = 07:30\n",
"escape \\e": 'bell = "\\e[1m"\n',
}
print(sys.version_info[:2])
for name, text in documents.items():
try:
print(f"{name}: {tomllib.loads(text)}")
except tomllib.TOMLDecodeError as error:
print(f"{name}: TOMLDecodeError: {error}")
(3, 14)
multi-line inline table: TOMLDecodeError: Invalid initial character for a key part (at line 1, column 10)
time without seconds: TOMLDecodeError: Expected newline or end of document after a statement (at line 1, column 10)
escape \e: TOMLDecodeError: Unescaped '\' in a string (at line 1, column 11)
- Verdict: stdlib, read only. Python 3.11 added
tomllib. It parses withtomllib.loads(a string) andtomllib.load(a binary file). It has no function to write TOML. loadneeds a file opened in binary mode. A file opened in text mode raisesTypeError.3.14159as a key makes a nested table, and a quoted key can hold a dot. A literal string keeps backslashes as they are. A backslash at the end of a line in a multi-line basic string removes the newline and the indentation that follow it.json.dumpswrites a character outside the Basic Multilingual Plane as two surrogate escapes. TOML rejects them, so a JSON string is not always a TOML string.ensure_ascii=False, or the escape\U0001F600, gives a valid value.- The
tomllibof Python 3.14 implements TOML 1.0.0, so it rejects the syntax that TOML 1.1.0 added: inline tables over several lines, times without seconds and the escape\e. - To write TOML, use a package from PyPI such as Tomli-W. To change a file and keep its comments, use TOML Kit.
import org.tomlj.Toml;
import org.tomlj.TomlArray;
import org.tomlj.TomlParseResult;
public class Main {
public static void main(String[] args) {
String text = """
# Billing service
name = "billing"
port = 8080 # the public port
started = 2026-11-10T09:30:00+07:00
cutoff = 2026-11-10T17:00:00
holiday = 2026-12-25
backup = 02:30:00
[database]
url = 'postgres://db.local/billing'
[[worker]]
queue = "invoices"
""";
TomlParseResult config = Toml.parse(text);
System.out.println(config.hasErrors());
System.out.println(config.getString("name") + " " + config.getLong("port"));
System.out.println(config.getOffsetDateTime("started").toInstant());
System.out.println(config.getLocalDateTime("cutoff") + " " + config.getLocalDate("holiday") + " " + config.getLocalTime("backup"));
System.out.println(config.getString("database.url"));
TomlArray workers = config.getArray("worker");
System.out.println(workers.getTable(0).getString("queue"));
System.out.println(config.toJson());
config.set("port", 9090L);
System.out.print(config.toToml());
}
}
false
billing 8080
2026-11-10T02:30:00Z
2026-11-10T17:00 2026-12-25 02:30
postgres://db.local/billing
invoices
{
"name" : "billing",
"port" : 8080,
"started" : "2026-11-10T09:30:00+07:00",
"cutoff" : "2026-11-10T17:00:00",
"holiday" : "2026-12-25",
"backup" : "02:30:00",
"database" : {
"url" : "postgres://db.local/billing"
},
"worker" : [{
"queue" : "invoices"
}]
}
# Billing service
name = "billing"
port = 9090 # the public port
started = 2026-11-10T09:30:00+07:00
cutoff = 2026-11-10T17:00:00
holiday = 2026-12-25
backup = 02:30:00
[database]
url = 'postgres://db.local/billing'
[[worker]]
queue = "invoices"
import org.tomlj.Toml;
import org.tomlj.TomlParseResult;
import org.tomlj.TomlVersion;
public class Main {
public static void main(String[] args) {
TomlParseResult bad = Toml.parse("[fruit]\napple = 1\n[fruit]\npear = 2\nlimit = 9223372036854775808\n");
System.out.println(bad.hasErrors());
bad.errors().forEach(error -> System.out.println(error));
String newer = "point = {\n x = 1,\n y = 2,\n}\n";
System.out.println(Toml.parse(newer).errors().size());
Toml.parse(newer, TomlVersion.V1_0_0).errors().forEach(error -> System.out.println(error));
}
}
true
fruit previously defined at line 1, column 1 (line 3, column 1)
Integer is too large (line 5, column 9)
0
Newlines are not allowed in an inline table (TOML versions before 1.1.0) (line 1, column 10)
- Verdict: library. Java SE has no TOML API. The examples use TomlJ 2.2.0.
Toml.parsenever throws on bad input. It returns aTomlParseResultthat holds the table and a list ofTomlParseErrorvalues, each with a line and a column. One parse can report more than one error.- The getters take a dotted key, as in
getString("database.url"). The date and time types map toOffsetDateTime,LocalDateTime,LocalDateandLocalTimefromjava.time. toTomlwrites the table again, and it keeps the comments and the literal strings of the input. Afterset("port", 9090L), the comment at the end of the line stays.toJsonwrites the same data as JSON.- An integer outside the 64-bit range is an error, as TOML 1.0.0 requires.
- TomlJ parses TOML 1.1.0 by default.
TomlVersion.V1_0_0rejects the forms that 1.1.0 added, such as an inline table over several lines.
use serde::{Deserialize, Serialize};
use toml::value::Datetime;
#[derive(Debug, Serialize, Deserialize)]
struct Config {
name: String,
port: u16,
started: Datetime,
hosts: Vec<String>,
database: Database,
}
#[derive(Debug, Serialize, Deserialize)]
struct Database {
url: String,
pool_size: u32,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let text = r#"
name = "billing"
port = 8080
started = 2026-11-10T09:30:00+07:00
hosts = ["alpha", "beta"]
[database]
url = 'postgres://db.local/billing'
pool_size = 10
"#;
let config: Config = toml::from_str(text)?;
println!("{} {} {} {:?}", config.name, config.port, config.started, config.hosts);
print!("{}", toml::to_string(&config)?);
println!("---");
let table: toml::Table = text.parse()?;
println!("{}", table["database"]["pool_size"]);
println!("{}", table["started"]);
match toml::from_str::<Config>(&text.replace("8080", "70000")) {
Ok(_) => println!("accepted"),
Err(error) => print!("{error}"),
}
println!("---");
match "limit = 9223372036854775808".parse::<toml::Table>() {
Ok(table) => println!("{table:?}"),
Err(error) => print!("{error}"),
}
Ok(())
}
billing 8080 2026-11-10T09:30:00+07:00 ["alpha", "beta"]
name = "billing"
port = 8080
started = 2026-11-10T09:30:00+07:00
hosts = ["alpha", "beta"]
[database]
url = "postgres://db.local/billing"
pool_size = 10
---
10
2026-11-10T09:30:00+07:00
TOML parse error at line 3, column 8
|
3 | port = 70000
| ^^^^^
invalid value: integer `70000`, expected u16
---
TOML parse error at line 1, column 9
|
1 | limit = 9223372036854775808
| ^^^^^^^^^^^^^^^^^^^
u64 value was too large
use toml_edit::{DocumentMut, value};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let text = r#"# Billing service
name = "billing"
port = 8080 # the public port
[database]
url = 'postgres://db.local/billing'
"#;
let mut document: DocumentMut = text.parse()?;
document["name"] = value("invoices");
document["port"] = value(9090);
document["database"]["pool_size"] = value(10);
print!("{document}");
println!("---");
let table: toml::Table = text.parse()?;
print!("{}", toml::to_string(&table)?);
println!("---");
let newer = "point = {\n x = 1,\n y = 2,\n}\nalarm = 07:30\n";
let table: toml::Table = newer.parse()?;
println!("{} {}", table["point"], table["alarm"]);
Ok(())
}
# Billing service
name = "invoices"
port = 9090
[database]
url = 'postgres://db.local/billing'
pool_size = 10
---
name = "billing"
port = 8080
[database]
url = "postgres://db.local/billing"
---
{ x = 1, y = 2 } 07:30
- Verdict: library. The Rust standard library has no TOML. The examples use the crates
toml1.2.1 andtoml_edit0.25.19, withserde1.0.229 and thederivefeature. The documentation oftomlsays that Cargo uses it. toml::from_strmaps a document to a type that implementsDeserialize, andtoml::to_stringwrites a type that implementsSerialize.toml::Tableis a map oftoml::Value, with no fixed type.- A TOML datetime becomes
toml::value::Datetime, which prints in the TOML form with its offset. - A value that does not fit the field type is an error with the line and the column, so
port = 70000fails for au16.toml::Valuekeeps integers asi64, so2^63is an error, as TOML 1.0.0 requires. toml_edit::DocumentMutkeeps comments, spaces and the order of keys. Butdocument["port"] = value(9090)drops the comment at the end of that line, because the replacement value has no comment.toml::to_stringof a parsedTabledrops every comment, and it writes the literal string as a basic string.- The crate version names the TOML version, as in
1.2.1+spec-1.1.0. It parses the TOML 1.1.0 forms: an inline table over several lines and a time without seconds.
Versions
| Version | Date | Main changes |
|---|---|---|
| 0.1.0 | 17 March 2013 | the first release3 |
| 0.2.0 | 24 September 2013 | "tables" replace "key groups"; arrays of tables3 |
| 0.3.0 | 10 November 2014 | exponents in floats; multi-line and literal strings; RFC 3339 datetimes3 |
| 0.4.0 | 12 February 2015 | inline tables; underscores in numbers; Unicode escapes must be scalar values3 |
| 0.5.0 | 11 July 2018 | dotted keys; hexadecimal, octal and binary integers; inf and nan; local date-time, local date and local time; the ABNF grammar; the extension .toml and the media type application/toml3 |
| 1.0.0-rc.1 | 1 April 2020 | arrays with values of different types; raw tabs in basic strings; inline tables are immutable3 |
| 1.0.0 | 11 January 2021 | clarifications about how tables are created and defined, and about the root table3 |
| 1.1.0 | 18 December 2025 | newlines and trailing commas in inline tables; the escapes \xHH and \e; seconds are optional in times3 |
Before 1.0.0, all values of an array had to have the same type. The release candidate 1.0.0-rc.1 removed this rule, so [1, "two"] is valid in 1.0.0.3
Version 1.1.0 is the first release after 1.0.0 that changes the syntax. In 1.0.0, an inline table must be on one line and must not have a trailing comma.1 In 1.1.0, it can span lines and can end with a comma. A basic string can use \xHH for a code point up to 255 and \e for the escape character U+001B. A time can leave out the seconds, as in 07:32, and :00 is assumed.2 A document that uses these forms is not valid TOML 1.0.0, so a parser of 1.0.0 rejects it. Check which version a parser implements before a file uses the forms of 1.1.0. The documentation of tomllib in Python 3.14 names TOML 1.0.0.7 The release notes of Python 3.15 say that its tomllib supports TOML 1.1.0.9 The Rust crate toml puts the version of the specification in its own version string, as in 1.2.1+spec-1.1.0.10
Pitfalls
- A table defined twice. Two
[name]headers, a header after dotted keys for the same table, or dotted keys that add to a header table are all errors. Keep all the keys of a table under one header. - A dotted key that looks like a number.
3.14159 = "pi"is the table3with the key14159.2 - Inline tables are closed. An inline table cannot be extended later. Use a
[table]header when other parts of the file must add keys.2 - Integers outside 64 bits. A parser with 64-bit integers raises an error for 2^63, and Python returns the exact value. A file that needs such numbers does not move well between languages. Write them as strings.
- Floats in money.
0.10becomes the nearest binary64 value in most parsers. Useparse_float=Decimalin Python, or store the amount as an integer of the smallest unit, or as a string. - Local date and time values have no zone.
2026-11-10T17:00:00is not an instant. The program must choose a zone, and two programs can choose differently.2 Write an offset when the value is an instant. - No null. TOML has no null value. Leave the key out, and let the program apply a default.2
- The order of keys. The specification does not guarantee an order for the pairs of a table.2 A program that needs an order must use an array.
- Writers lose comments. A program that parses a file into maps and writes it again loses the comments and the layout. PEP 680 gives this as a reason why
tomllibhas no writer.8 Use a library that keeps the format, such astoml_editin Rust or TomlJ in Java, to change a file that people edit.1112 Test the edit: in the Rust example,toml_editdrops the comment at the end of a line when the program replaces the value on that line. tomllibis read-only. The module has nodumpfunction. Its documentation names the packages Tomli-W, to write TOML, and TOML Kit, to edit TOML and keep its style.7- Strings written by a JSON encoder. A JSON string is not always a valid TOML basic string. JSON writes a character outside the Basic Multilingual Plane as two
\uescapes of surrogates, and TOML rejects an escape that is not a scalar value.2 The Python example file shows this. - The TOML version of the parser. A file with multi-line inline tables or times without seconds is valid in 1.1.0 and invalid in 1.0.0.
- Untrusted input. The documentation of
tomllibwarns that a malicious document can make the parser use much CPU time and memory. Limit the size of the input.7
Tools and libraries
| Language | Verdict | Parse and write |
|---|---|---|
| Python | stdlib (read only) | tomllib.load, tomllib.loads; Tomli-W and TOML Kit to write7 |
| Rust | library | toml::from_str, toml::to_string; toml_edit::DocumentMut to edit a file and keep its format1011 |
| Java | library | TomlJ Toml.parse, toToml12 |
| Go | library | BurntSushi/toml, go-toml v21617 |
| JavaScript, TypeScript | library | smol-toml18 |
| C# | library | Tomlyn19 |
| C++ | library | toml++20 |
| Kotlin | library | ktoml, or a Java library on the JVM22 |
| Bash | library | the command-line tool yq reads and writes TOML21 |
The project toml-test is a test suite for TOML parsers and writers, independent of any language. It has valid documents, which a decoder must turn into the expected JSON, and invalid documents, which it must reject.15 The READMEs of BurntSushi/toml, go-toml v2, smol-toml, Tomlyn and toml++ each say that the library supports TOML 1.1.0.1617181920
References
- T. Preston-Werner, P. Gedam, et al., TOML v1.0.0, 11 January 2021, Preliminaries; Keys; String; Integer; Float; Offset Date-Time; Local Date-Time; Inline Table
- T. Preston-Werner, P. Gedam, et al., TOML v1.1.0, 18 December 2025, Objectives; Preliminaries; Comment; Keys; String; Integer; Float; Offset Date-Time; Local Date-Time; Array; Table; Inline Table; Array of Tables; Filename Extension; MIME Type
- TOML Changelog, the entries 0.1.0, 0.2.0, 0.3.0, 0.4.0, 0.5.0, 1.0.0-rc.1, 1.0.0 and 1.1.0
- TOML ABNF grammar, at the tag 1.1.0, the rules toml, expression, keyval, key, date-time, table, std-table, inline-table and array-table
- TOML README, Objectives; Comparison with Other Formats
- IANA, Media Types registry, the application registry, the entry toml
- The Python Standard Library, tomllib, Python 3.14, the introduction; tomllib.load; tomllib.loads; TOMLDecodeError; Conversion Table
- T. Hukkinen, S. Jain, PEP 680: tomllib: Support for Parsing TOML in the Standard Library, 2022, Motivation; Rationale; Security Implications; Rejected Ideas, Including an API for writing TOML
- What's New In Python 3.15, Improved modules, tomllib
- toml 1.2.1+spec-1.1.0 documentation, the crate documentation, TOML values, from_str and to_string
- toml_edit 0.25.19+spec-1.1.0 documentation, the crate documentation, Example and Limitations
- TomlJ, the README, Error reporting and recovery; Other highlights
- The Cargo Book, The Manifest Format, the first paragraph
- B. Cannon, N. Smith, D. Stufft, PEP 518: Specifying Minimum Build System Requirements for Python Projects, 2016, Abstract; Overview of file formats considered
- toml-test, the README, the first paragraphs
- BurntSushi/toml, TOML parser for Go, the README, the first paragraph
- go-toml v2, the README, the first paragraph and Stdlib behavior
- smol-toml, the README, the first paragraph
- Tomlyn, the README, Features
- toml++ (tomlplusplus), the README, Library features
- yq, the README, the input and output formats
- ktoml, the README
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag RR1JRW Edit this page History Report an error Markdown