dump_universal
Class info¶
🛈 DocStrings¶
dump
¶
Dump data to a string in the specified format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
Data structure to dump (also accepts pydantic v2 models and dataclasses) |
required |
mode
|
SupportedFormats
|
Format to dump the data in ("yaml", "toml", "json", or "ini") |
required |
**kwargs
|
Any
|
Additional keyword arguments passed to the underlying dump functions |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
String containing the formatted data |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the format is not supported |
DumpingError
|
If the data cannot be dumped in the specified format |
Source code in src/configz/dump_universal.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
dump_file
¶
dump_file(
data: Any,
path: JoinablePathLike,
mode: FormatType = "auto",
overwrite: bool = False,
create_dirs: bool = False,
**kwargs: Any,
) -> None
Dump data to a file, automatically detecting the format from extension if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
Data structure to dump |
required |
path
|
JoinablePathLike
|
Path to the file to write |
required |
mode
|
FormatType
|
Format to write the file in ("yaml", "toml", "json", "ini" or "auto") |
'auto'
|
overwrite
|
bool
|
Whether to overwrite the file if it already exists |
False
|
create_dirs
|
bool
|
Whether to create parent directories if they don't exist |
False
|
**kwargs
|
Any
|
Additional keyword arguments passed to the underlying dump functions |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the format cannot be determined or is not supported |
DumpingError
|
If the data cannot be dumped or the file cannot be written |