load_universal
Class info¶
🛈 DocStrings¶
load
¶
load(
text: str,
mode: SupportedFormats,
verify_type: type[T] | None = None,
resolve_inherit: bool | JoinablePathLike = False,
resolve_env_vars: bool = False,
inherit_from: list[str] | str | None = None,
**kwargs: Any,
) -> Any | T
Load data from a string in the specified format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
String containing data in the specified format |
required |
mode
|
SupportedFormats
|
Format of the input data ("yaml", "toml", "json", or "ini") |
required |
verify_type
|
type[T] | None
|
Type to verify and cast the output to (supports TypedDict) |
None
|
resolve_inherit
|
bool | JoinablePathLike
|
Whether to resolve inheritance in the loaded data |
False
|
resolve_env_vars
|
bool
|
Whether to resolve {env:VAR_NAME} or {env:VAR_NAME:default} patterns |
False
|
inherit_from
|
list[str] | str | None
|
Additional paths to inherit from. These form the base layer, meaning explicit INHERIT directives in the file take precedence. |
None
|
**kwargs
|
Any
|
Additional keyword arguments passed to the underlying load functions |
{}
|
Returns:
| Type | Description |
|---|---|
Any | T
|
Parsed data structure, typed according to verify_type if provided |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the format is not supported |
ParsingError
|
If the text cannot be parsed in the specified format |
TypeError
|
If verify_type is provided and the loaded data doesn't match |
Example
Source code in src/configz/load_universal.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
load_file
¶
load_file(
path: JoinablePathLike,
mode: FormatType = "auto",
*,
storage_options: dict[str, Any] | None = None,
verify_type: type[T] | None = None,
resolve_inherit: bool = True,
resolve_env_vars: bool = False,
inherit_from: list[str] | str | None = None,
) -> Any | T
Load data from a file, automatically detecting the format from extension if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
JoinablePathLike
|
Path to the file to load |
required |
mode
|
FormatType
|
Format of the file ("yaml", "toml", "json", "ini" or "auto") |
'auto'
|
storage_options
|
dict[str, Any] | None
|
Additional keyword arguments to pass to the fsspec backend |
None
|
verify_type
|
type[T] | None
|
Type to verify and cast the output to (supports TypedDict) |
None
|
resolve_inherit
|
bool
|
Whether to resolve inheritance in the loaded data |
True
|
resolve_env_vars
|
bool
|
Whether to resolve {env:VAR_NAME} or {env:VAR_NAME:default} patterns |
False
|
inherit_from
|
list[str] | str | None
|
Additional paths to inherit from. These form the base layer, meaning explicit INHERIT directives in the file take precedence. |
None
|
Returns:
| Type | Description |
|---|---|
Any | T
|
Parsed data structure, typed according to verify_type if provided |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the format cannot be determined or is not supported |
OSError
|
If the file cannot be read |
FileNotFoundError
|
If the file does not exist |
PermissionError
|
If file permissions prevent reading |
ParsingError
|
If the text cannot be parsed in the specified format |
TypeError
|
If verify_type is provided and the loaded data doesn't match |
Example
Source code in src/configz/load_universal.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |