import base64


def get_svg(path):
    """Get an svg image into format to properly display

    This formats the svg image found at `path` into the str necessary
    for displaying in a dcc.Img component.

    from https://github.com/plotly/dash/issues/537

    Parameters
    ----------
    path : str
        path to the svg image

    Returns
    -------
    src : str
        The str to pass as src to a dcc.Img component. Note that this
        will contain the decoded svg image (as text) and so will be
        quite long
    """
    svg = base64.b64encode(open(path, 'rb').read())
    return 'data:image/svg+xml;base64,{}'.format(svg.decode())