TOML Configuration
TOML maps configuration data to hash tables using explicit key-value syntax with native types for strings, integers, floats, booleans, datetimes, arrays, and tables. It is the config format for Rust (Cargo.toml) and Python (pyproject.toml).
Configuration format. Conversion between config formats requires semantic mapping.
أسئلة شائعة
What is the difference between TOML and YAML for configuration?
TOML has explicit types with no implicit coercion — a value's type is always determined by its syntax. YAML silently converts unquoted strings like 'yes', 'no', and 'null' to booleans and null. TOML is designed for flat-to-moderately-nested configuration. YAML handles deeply nested structures better.
Why does Rust use TOML instead of JSON or YAML?
Cargo adopted TOML because it supports comments (JSON does not), has unambiguous types (YAML does not), and maps directly to Rust's type system. The lack of implicit coercion makes TOML safe to parse without surprising behavior, which matters for a build system processing untrusted package manifests.
How do I use arrays of tables in TOML?
Double-bracket headers ([[products]]) define arrays of tables. Each [[products]] section appends a new element to the array. This syntax represents what JSON would write as [{...}, {...}]. It is used in Cargo.toml for [[bin]], [[example]], and [[bench]] sections.
Does Python have built-in TOML support?
Python 3.11+ includes tomllib in the standard library for reading TOML files. For Python 3.7-3.10, use the tomli package (pip install tomli), which is the same code that became tomllib. For writing TOML, use the tomli-w package — tomllib is read-only.
ما يميز .TOML
What is a TOML file?
TOML (Tom's Obvious, Minimal Language) is a configuration file format created by GitHub co-founder Tom Preston-Werner. It is designed to be minimal and unambiguous, mapping directly to a hash table. TOML is used as the configuration format for Rust (Cargo.toml), Python (pyproject.toml), and many other tools.
اكتشف التفاصيل التقنية
How to open TOML files
- VS Code (Windows, macOS, Linux) — With Even Better TOML extension
- Any text editor — TOML files are plain text
- toml (Python) —
pip install tomlfor parsing - toml-rs (Rust) — Native TOML parsing
Technical specifications
| Property | Value |
|---|---|
| Version | TOML v1.0.0 (2021) |
| Encoding | UTF-8 |
| Data Types | String, integer, float, boolean, datetime, array, table |
| Comments | Hash (#) line comments |
| Nesting | Dot-separated keys or [table] headers |
Common use cases
- Rust projects: Cargo.toml package configuration.
- Python projects: pyproject.toml build configuration.
- Go modules: go.mod companion configuration.
- Static site generators: Hugo, Pelican configuration.
المرجع التقني
- نوع MIME
application/toml- المطوّر
- Tom Preston-Werner
- سنة التقديم
- 2013
- معيار مفتوح
- نعم — عرض المواصفات
البنية الثنائية
TOML is a text format with no binary structure. A TOML file consists of key-value pairs organized into tables. Top-level key-value pairs exist in the root table. Tables are declared with [table-name] headers, creating named sub-objects. Dotted keys (server.port = 8080) create implicit intermediate tables. Arrays of tables use [[array-name]] double-bracket headers, with each occurrence appending a new element. Keys can be bare (alphanumeric, dash, underscore), quoted with double quotes, or quoted with single quotes (literal). Values have explicit types: strings (basic with escapes or literal with no escapes), integers (decimal, hex 0x, octal 0o, binary 0b, with _ separators), floats (IEEE 754, including inf and nan), booleans (true/false, lowercase only), datetimes (RFC 3339 with optional timezone), local dates, local times, arrays (comma-separated in square brackets, typed but mixed types allowed), and inline tables ({key = value} on one line). Comments begin with # and extend to end of line. TOML is always encoded in UTF-8. Unlike YAML, TOML has no implicit type coercion — every value's type is determined unambiguously by its syntax.
نقاط الضعف
- Denial of service via extremely large arrays or deeply nested inline tables — a crafted TOML file with millions of array elements can exhaust parser memory
- Duplicate key exploitation — TOML forbids duplicate keys, but non-compliant parsers that accept duplicates may use inconsistent values, causing configuration logic errors
الحماية: FileDex processes TOML files entirely in the browser as text. No execution of values, no external resource loading, no server-side parsing. TOML has no code execution mechanism in its specification.