EDIT: for a very safe way to generate random numbers, you should use urandom:
from binascii import hexlify
key = hexlify(os.urandom(lenght))
this will create bytes, call key.decode()if you need a string
You can simply generate the keys of the desired length in the python path:
import random
import string
def generate_key(length):
return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(length))
key = generate_key(40).
, , , string.ascii_lowercase , ..
Api tastypie, , https://django-tastypie.readthedocs.org/en/latest/authentication.html#apikeyauthentication