ShortUUID

1.0.13 · active · verified Thu Apr 09

Shortuuid is a Python library that generates concise, unambiguous, and URL-safe UUIDs. It provides a simple API to generate UUIDs, encode integers, and decode strings using a customizable alphabet. The current version is 1.0.13, and releases are infrequent but stable, with a focus on maintenance.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to generate short UUIDs, specify their length, and encode/decode integers using the default and a custom alphabet.

import shortuuid

# Generate a standard short UUID (default length 22)
my_uuid = shortuuid.uuid()
print(f"Generated UUID: {my_uuid}")

# Generate a UUID of a specific length
short_uuid_10 = shortuuid.uuid(length=10)
print(f"10-char UUID: {short_uuid_10}")

# Encode an integer to a short UUID string
encoded_str = shortuuid.encode(123456789)
print(f"Encoded integer: {encoded_str}")

# Decode a short UUID string back to an integer
decoded_int = shortuuid.decode(encoded_str)
print(f"Decoded integer: {decoded_int}")

# Use a custom alphabet
custom_su = shortuuid.ShortUUID(alphabet="0123456789abcdef")
custom_uuid = custom_su.uuid()
print(f"Custom alphabet UUID: {custom_uuid}")

view raw JSON →