Yaml
provide.foundation.serialization.yaml
¶
TODO: Add module docstring.
Functions¶
yaml_dumps
¶
yaml_dumps(
obj: Any,
*,
default_flow_style: bool = False,
allow_unicode: bool = True,
sort_keys: bool = False
) -> str
Serialize object to YAML string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
Object to serialize |
required |
default_flow_style
|
bool
|
Use flow style (JSON-like) instead of block style |
False
|
allow_unicode
|
bool
|
If True, allow unicode characters |
True
|
sort_keys
|
bool
|
Whether to sort dictionary keys |
False
|
Returns:
| Type | Description |
|---|---|
str
|
YAML string representation |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If object cannot be serialized |
ImportError
|
If PyYAML is not installed |
Example
yaml_dumps({"key": "value"}) 'key: value\n'
Source code in provide/foundation/serialization/yaml.py
yaml_loads
¶
Deserialize YAML string to Python object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
YAML string to deserialize |
required |
use_cache
|
bool
|
Whether to use caching for this operation |
True
|
Returns:
| Type | Description |
|---|---|
Any
|
Deserialized Python object |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If string is not valid YAML |
ImportError
|
If PyYAML is not installed |
Example
yaml_loads('key: value') {'key': 'value'} yaml_loads('[1, 2, 3]') [1, 2, 3]