import yaml


def safe_dump(data, stream=None, **kwds):
    """
    Serialize a Python object into a YAML stream.
    If stream is None, return the produced string instead.
    """
    return yaml.safe_dump(data, stream, **kwds)