def buid():
    """
    Return a new random id that is exactly 22 characters long,
    by encoding a UUID4 in URL-safe Base64. See
    http://en.wikipedia.org/wiki/Base64#Variants_summary_table

    >>> len(buid())
    22
    >>> buid() == buid()
    False
    >>> isinstance(buid(), six.text_type)
    True
    """
    if six.PY3:  # pragma: no cover
        return urlsafe_b64encode(uuid.uuid4().bytes).decode('utf-8').rstrip('=')
    else:  # pragma: no cover
        return six.text_type(urlsafe_b64encode(uuid.uuid4().bytes).rstrip('='))