write_yaml()function

Write a Python value to YAML at path or stdout.

USAGE

write_yaml(
    value,
    path=None,
    multi=False,
)

Parameters

value : object

Python value or Yaml to serialize; for multi the value must be a sequence of documents.

path : str | os.PathLike | text file-like | None = None

Destination path or object with .write(str); when None the YAML is written to stdout.

multi : bool = False

Emit a multi-document stream when true; otherwise a single document.

Returns

None

None

Raises

IOError

When writing to the file or stdout fails.

TypeError

When multi is true and value is not a sequence, or unsupported types are provided.

Examples

>>> write_yaml({'foo': 1}, path='out.yml')
>>> Path('out.yml').exists()
True
>>> write_yaml(['first', 'second'], multi=True)  # prints YAML ending with '...'