Compact URL numbering format hexahexacontadecimal now on PyPI

I recently came across a StackOverFlow question asking “How to convert an integer to the shortest url-safe string in Python?” The answer is still hexahexacontadecimal but I realised I never actually posted the decoding snippet. So today I’m putting the whole module up on PyPI for easy installation with pip.


pip install hexahexacontadecimal

Then in Python:

from hexahexacontadecimal import hexahexacontadecimal_encode_int, hexahexacontadecimal_decode_int

print hexahexacontadecimal_encode_int(302231454903657293676544)  # 'iFsGUkO.0tsxw'
print hexahexacontadecimal_decode_int('iFsGUkO.0tsxw')           # 302231454903657293676544L

With Pyle:

echo 302231454903657293676544 | pyle -m hexahexacontadecimal -e "hexahexacontadecimal.hexahexacontadecimal_encode_int(int(line))"

Enjoy the ultimate compactness of your random1 numeric URLs.

PyPI package

GitHub Repo

1: If your number is truly random, a compression algorithm like gzip would not improve on this, on average.

Subscribe Tweet This
Written by Alexander Ljungberg on 2013 Aug 1 .