-
-
Save jihchi/6419619 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Generate URL-safe UUID/GUIDs in Python, e.g. | |
# | |
# ob9G9Ju_Re6SRgxacdUzhw | |
# k0CWKgThQq-9b2ZcmpVXXA | |
# | |
# base64 has an urlsafe encoding | |
from base64 import urlsafe_b64encode | |
# any of uuid1, uuid3, uuid4 or uuid5 will do | |
# see http://docs.python.org/2/library/uuid.html | |
from uuid import uuid4 as uuid | |
# generate a uuid and base64 encode it | |
# drop trailing "==", add it back if decoding | |
print urlsafe_b64encode(uuid().bytes)[0:22] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment