import hashlib
import six


def create_hash(inp, l=10, algo="sha256", to_int=False):
    """
    Takes an arbitrary input *inp* and creates a hexadecimal string hash based on an algorithm
    *algo*. For valid algorithms, see python's hashlib. *l* corresponds to the maximum length of the
    returned hash and is limited by the length of the hexadecimal representation produced by the
    hashing algorithm. When *to_int* is *True*, the decimal integer representation is returned.
    """
    h = getattr(hashlib, algo)(six.b(str(inp))).hexdigest()[:l]
    return int(h, 16) if to_int else h