parse_yaml()function
Parse YAML text into Python values.
USAGE
parse_yaml(text: str | Iterable[str], multi: Literal[False] = False, handlers: None = None) -> _YamlOutput
parse_yaml(text: str | Iterable[str], multi: Literal[True], handlers: None = None) -> list[_YamlOutput]
parse_yaml(text: str | Iterable[str], multi: bool = False, handlers: Mapping[str, Callable[[Any], Any]] | None = None) -> AnyParameters
text : str | Iterable[str]-
YAML text, or an iterable yielding text chunks. Chunks are concatenated exactly as provided (no implicit separators are inserted).
multi : bool = False-
Return a list of documents when true; otherwise a single document or None for empty input.
handlers : dict[str, Callable] | None = None-
Optional tag handlers for values and keys; matching handlers receive the parsed value.
Returns
object-
Parsed value(s): YAML mappings become
dict, sequences becomelist, and scalars resolve using the YAML 1.2 core schema tobool/int/float/None/str. Unhashable mapping keys (for examplelist/dict) are wrapped in the lightweightYamlwrapper to keep them hashable. Tagged nodes without a matching handler are also wrapped inYamlso the tag can be preserved.
Raises
ValueError-
On YAML parse errors or invalid tag strings.
TypeError-
When inputs are the wrong type or handlers are not callables.
Exception-
Propagated directly from user-provided handlers.
Examples
>>> parse_yaml('foo: 1\nbar: true')
{'foo': 1, 'bar': True}