def generate_api_key():
    """
    Generates an sufficiently large and random key.

    credit: http://jetfar.com/simple-api-key-generation-in-python/

    :rtype: ``str``
    """
    # 256bit seed from urandom
    seed = os.urandom(256)

    # since urandom does not provide sufficient entropy hash, base64encode and salt.
    # The resulting value is now large and should be hard to predict.
    hashed_seed = hashlib.sha256(seed).hexdigest()

    base64_encoded = base64.b64encode(
        six.b(hashed_seed),
        six.b(random.choice(["rA", "aZ", "gQ", "hH", "hG", "aR", "DD"])),
    ).rstrip(b"==")
    base64_encoded = base64_encoded.decode()
    return base64_encoded

    Generates an sufficiently large and random key.

    credit: http://jetfar.com/simple-api-key-generation-in-python/

    :rtype: ``str``
    
st2common/st2common/util/auth.py