TOML Format
Lodum provides TOML support usingtomllib (Python 3.11+) or tomli for reading and tomli-w for writing.
Installation
TOML support requires additional dependencies:tomli-wfor serializationtomlifor deserialization (Python < 3.11)tomllibis used on Python 3.11+ (built-in)
API Reference
dump()
obj: The object to encode (must be a@lodum-decorated class)target: Optional file-like object or Path to write to**kwargs: Additional arguments fortomli_w.dump(s)
- The TOML string if
targetis None, otherwise None
dumps()
dump(obj). Provided for compatibility.
load()
cls: The class to instantiatesource: TOML string, file-like object, or Pathmax_size: Maximum allowed size for string input (default: 10MB)
- An instance of
clspopulated with the decoded data
loads()
load(cls, source). Provided for compatibility.
schema()
Binary Data Handling
TOML doesn’t natively support binary data. Lodum automatically encodesbytes fields using base64:
TOML Limitations
TOML has some structural limitations compared to JSON and YAML:- No streaming support: TOML doesn’t support multi-document streams like YAML
- Table structure: Complex nested structures are represented as TOML tables
- Type constraints: TOML has stricter type requirements (e.g., arrays must be homogeneous)
Use Cases
TOML is ideal for:- Configuration files (see
pyproject.toml) - Application settings
- Human-editable structured data
- Large datasets
- Streaming data
- Binary data
- Highly nested or complex structures