write_yaml() serializes Python data to YAML and writes it to disk.
write_yaml(
file_path: str | Path,
data: Any,
create_if_missing: bool = True,
allow_unicode: bool = True,
sort_keys: bool = False,
on_error: Literal["raise", "log", "silent"] | None = None,
) -> Nonefrom clevertools import write_yaml
write_yaml(
"config.yaml",
{
"service": "clevertools",
"enabled": True,
"labels": ["yaml", "config"],
},
allow_unicode=True,
sort_keys=False,
)from clevertools import write_yaml
write_yaml(
"content/meta.yaml",
{"title": "Überblick", "language": "de"},
allow_unicode=True,
)datamust not beNone.- With
create_if_missing=True, parent folders are created automatically. sort_keys=Falseis useful when output order should stay close to your input structure.