You are nobody without an API Key generator

API KEYs are sexy: if you have a web based business (like Google, Twitter, Facebook or WordPress’Automattic) you should have a way to generate an API Key for web service integration.

Like Session keys, API keys should be sufficiently unpredictable to be psuedo-random. To be unpredictable, no user variables (or timestamps) are encoded into the key.

A small pythonic way to do the trick is this piece of code:

import hashlib, random
hashlib.sha224( str(random.getrandbits(256)) ).hexdigest();

you can also shell-ize it :

python -c 'import hashlib, random ; print hashlib.sha224( str(random.getrandbits(128)) ).hexdigest()'


Finally, for a longer  explanation take a look to this blog entry

Leave a Reply