import base64
import six


def serialize(obj):
    """Serialize the given object
    :param obj: string representation of the object
    :return: encoded object (its type is unicode string)
    """
    result = base64.urlsafe_b64encode(obj)
    # this workaround is needed because in case of python 3 the
    # urlsafe_b64encode method returns string of 'bytes' class.
    if six.PY3:
        result = result.decode()
    return result