def dump(data, stream=None, **kwargs):
    """
    Serialize YAMLDict into a YAML stream.
    If stream is None, return the produced string instead.
    """
    return yaml.dump_all(
        [data],
        stream=stream,
        Dumper=YAMLDictDumper,
        **kwargs
    )