YAML Format
Lodum provides YAML support using theruamel.yaml library, which supports YAML 1.2 and preserves formatting.
Installation
YAML support requires theruamel.yaml library:
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 foryaml.dump
- The YAML string if
targetis None, otherwise None
dumps()
dump(obj). Provided for compatibility.
load()
cls: The class to instantiatesource: YAML string, file-like object, or Pathmax_size: Maximum allowed size for string input (default: 10MB)
- An instance of
cls
loads()
load(cls, source). Provided for compatibility.
stream()
---).
Parameters:
cls: The class to instantiate for each itemsource: A stream, file-like object, or Path
- An iterator yielding instances of
cls
schema()
Binary Data Handling
YAML doesn’t natively support arbitrary binary data. Lodum encodesbytes fields using base64 for cross-format consistency:
YAML Configuration
Lodum usesruamel.yaml with safe mode enabled. The YAML instance is configured to:
- Use safe loading (typ=“safe”)
- Preserve key order (sort_base_mapping_type_on_output = False)