format_yaml()

Serialize a Python value to a YAML string.

Usage

format_yaml(
    value,
    multi=False,
    width=80,
)

Parameters

value: object

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

multi: bool = False

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

width: int | None = 80
Target maximum line width. None disables wrapping.

Returns

str: str
YAML text; each document in a multi-document stream begins with ---.

Raises

TypeError

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

ValueError
When width is less than one.

Examples

    >>> format_yaml({'foo': 1})
'foo: 1'
    >>> format_yaml(['first', 'second'], multi=True).endswith('second\n')
True