import six


def ensure_text(str_or_bytes, encoding='utf-8'):
    """Ensures an input is a string, decoding if it is bytes.
    """
    if not isinstance(str_or_bytes, six.text_type):
        return str_or_bytes.decode(encoding)
    return str_or_bytes