def num_to_alpha(num):
    num = hex(num)[2:].rstrip('L')
if len(num) % 2:
    num = '0' + num
return base64.b64encode(num.decode('hex'))
Encoding a numeric string into a shortened alphanumeric string, and back again