Compresses a string (or bytes) using Gzip and returns its Base64 representation

    :param data: string or bytes
    :return: Base64 (bytes) representation of compressed data

def compress(data):
    """
    Compresses a string (or bytes) using Gzip and returns its Base64 representation

    :param data: string or bytes
    :return: Base64 (bytes) representation of compressed data
    """

    if isinstance(data, bytes):
        source = data
    elif isinstance(data, str):
        source = bytes(data, encoding='utf-8')
    else:
        raise RuntimeError("Compression is only supported for strings and bytes")

    return base64.b64encode(gzip.compress(source))