def generate_key(key_length=64):
 if hasattr(random, 'SystemRandom'):
  logging.info('Generating a secure random key using SystemRandom.')
  choice = random.SystemRandom().choice
 else:
  msg = 'WARNING: SystemRandom not present. Generating a random key using random.choice (NOT CRYPTOGRAPHICALLY SECURE).'
  logging.warning(msg)
  choice = random.choice
 return ''.join(map((lambda x: choice((string.digits + string.ascii_letters))), range(key_length)))

def generate_key ( key_length = 64 ) : if hasattr ( random , 'SystemRandom' ) : logging . info ( 'Generating a secure random key using SystemRandom.' ) choice = random . SystemRandom ( ) . choice else : msg = 'WARNING: SystemRandom not present. Generating a random key using random.choice (NOT CRYPTOGRAPHICALLY SECURE).' logging . warning ( msg ) choice = random . choice return '' . join ( map ( ( lambda x : choice ( ( string . digits + string . ascii_letters ) ) ) , range ( key_length ) ) )
generate a random api key see: URL .