Skip to content

Instantly share code, notes, and snippets.

@mattupstate
Last active July 2, 2020 13:46
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mattupstate/8714628 to your computer and use it in GitHub Desktop.
Save mattupstate/8714628 to your computer and use it in GitHub Desktop.
Generate unique, URL friendly ID's based on UUID with Python
import re
import uuid
import base64
def uuid_url64():
"""Returns a unique, 16 byte, URL safe ID by combining UUID and Base64
"""
rv = base64.b64encode(uuid.uuid4().bytes).decode('utf-8')
return re.sub(r'[\=\+\/]', lambda m: {'+': '-', '/': '_', '=': ''}[m.group(0)], rv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment