import io


def export_python(palette):
    """
    Return a string of a Python tuple of every named colors.

    Arguments:
        palette (dict): Dictionnary of named colors (as dumped in JSON from
            ``colors`` command)

    Returns:
        string: Python tuple.
    """
    # Open Python tuple
    python_palette = io.StringIO()
    python_palette.write(u'colors = (\n')

    for original_code, values in sorted(palette.items(), key=lambda x:x[1]):
        name, from_color = values
        python_palette.write("    ('{}', '{}'),\n".format(name, original_code))

    # Close Python tuple
    python_palette.write(u')\n\n')

    output = python_palette.getvalue()

    python_palette.close()

    return output