Formats
provide.foundation.file.formats
¶
TODO: Add module docstring.
Functions¶
read_json
¶
Read JSON file with error handling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
JSON file path |
required |
default
|
Any
|
Default value if file doesn't exist or is invalid |
None
|
encoding
|
str
|
Text encoding |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
Any
|
Parsed JSON data or default value |
Source code in provide/foundation/file/formats.py
read_toml
¶
Read TOML file with error handling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
TOML file path |
required |
default
|
Any
|
Default value if file doesn't exist or is invalid |
None
|
encoding
|
str
|
Text encoding |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Parsed TOML data or default value |
Source code in provide/foundation/file/formats.py
read_yaml
¶
Read YAML file with error handling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
YAML file path |
required |
default
|
Any
|
Default value if file doesn't exist or is invalid |
None
|
encoding
|
str
|
Text encoding |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
Any
|
Parsed YAML data or default value |
Source code in provide/foundation/file/formats.py
write_json
¶
write_json(
path: Path | str,
data: Any,
indent: int = 2,
sort_keys: bool = False,
atomic: bool = True,
encoding: str = "utf-8",
) -> None
Write JSON file, optionally atomic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
JSON file path |
required |
data
|
Any
|
Data to serialize |
required |
indent
|
int
|
Indentation level (None for compact) |
2
|
sort_keys
|
bool
|
Whether to sort dictionary keys |
False
|
atomic
|
bool
|
Use atomic write |
True
|
encoding
|
str
|
Text encoding |
'utf-8'
|
Source code in provide/foundation/file/formats.py
write_toml
¶
write_toml(
path: Path | str,
data: dict[str, Any],
atomic: bool = True,
encoding: str = "utf-8",
) -> None
Write TOML file, optionally atomic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
TOML file path |
required |
data
|
dict[str, Any]
|
Data to serialize (must be a dictionary) |
required |
atomic
|
bool
|
Use atomic write |
True
|
encoding
|
str
|
Text encoding |
'utf-8'
|
Source code in provide/foundation/file/formats.py
write_yaml
¶
write_yaml(
path: Path | str,
data: Any,
atomic: bool = True,
encoding: str = "utf-8",
default_flow_style: bool = False,
) -> None
Write YAML file, optionally atomic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
YAML file path |
required |
data
|
Any
|
Data to serialize |
required |
atomic
|
bool
|
Use atomic write |
True
|
encoding
|
str
|
Text encoding |
'utf-8'
|
default_flow_style
|
bool
|
Use flow style (JSON-like) instead of block style |
False
|