shortuuid: Generate Concise, Unambiguous, and URL-Safe UUIDs in Python
This repository profile is provided by osrepos.com, an open source repository discovery platform.

Summary
shortuuid is a Python library designed to generate concise, unambiguous, and URL-safe UUIDs. It addresses the need for non-sequential IDs that are easy for users to read and use, by translating standard UUIDs to a base57 alphabet. This library ensures IDs are short, readable, and avoids similar-looking characters like 'l', '1', 'I', 'O', and '0'.
Repository Information
Topics
Click on any tag to explore related repositories
Use at your own risk
OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.
Introduction
shortuuid is a straightforward Python library that generates concise, unambiguous, and URL-safe UUIDs. It's particularly useful when you need non-sequential IDs that are visible to users and must be as short and easy to use as possible. The library achieves this by taking standard UUIDs, generated by Python's built-in uuid module, and translating them into a base57 representation. This base57 alphabet uses lowercase and uppercase letters and digits, carefully excluding characters that can be easily confused, such as 'l', '1', 'I', 'O', and '0'.
Installation
To install shortuuid, you will need Python 3.6+.
There are several installation options:
- With pip (preferred): Run
pip install shortuuid. - With setuptools: Run
easy_install shortuuid. - From source: Download the source from the GitHub repository and run
python setup.py install.
Examples
Here's how to use shortuuid in your projects:
Basic UUID Generation:
>>> import shortuuid
>>> shortuuid.uuid()
'vytxeTZskVKR7C7WgdSP3d'
Version 5 UUIDs with Namespaces:
>>> shortuuid.uuid(name="example.com")
'exu3DTbj2ncsn9tLdLWspw'
>>> shortuuid.uuid(name="<http://example.com>")
'shortuuid.uuid(name="<http://example.com>")'
Generating Random Strings:
>>> shortuuid.ShortUUID().random(length=22)
'RaF56o2r58hTKT7AYS9doj'
Inspecting and Setting the Alphabet:
>>> shortuuid.get_alphabet()
'23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
>>> shortuuid.set_alphabet("aaaaabcdefgh1230123")
>>> shortuuid.uuid()
'0agee20aa1hehebcagddhedddc0d2chhab3b'
Encoding and Decoding Existing UUIDs:
>>> import uuid
>>> u = uuid.uuid4()
>>> u
UUID('6ca4f0f8-2508-4bac-b8f1-5d1e3da2247a')
>>> s = shortuuid.encode(u)
>>> s
'MLpZDiEXM4VsUryR9oE8uc'
>>> shortuuid.decode(s) == u
True
Class-based Usage for Multiple Alphabets:
>>> su = shortuuid.ShortUUID(alphabet="01345678")
>>> su.uuid()
'034636353306816784480643806546503818874456'
Command-line Usage:
$ shortuuid
fZpeF6gcskHbSpTgpQCkcJ
Django Field Integration:
shortuuid also provides a Django field for convenience, allowing you to easily integrate short UUIDs into your models:
from shortuuid.django_fields import ShortUUIDField
class MyModel(models.Model):
id = ShortUUIDField(
length=16,
max_length=40,
prefix="id_",
alphabet="abcdefg1234",
primary_key=True,
)
api_key = ShortUUIDField()
Why Use It
shortuuid offers a compelling solution for generating identifiers that are both unique and user-friendly. Its core advantage lies in producing concise, unambiguous, and URL-safe IDs, which significantly improves readability and usability in contexts where IDs are exposed to users. By meticulously removing similar-looking characters from its alphabet, it minimizes confusion and errors. The library's flexibility, allowing custom alphabets and length truncation, makes it adaptable to various project requirements. Furthermore, its seamless integration with Django provides an easy way to incorporate these benefits into web applications.
Links
- GitHub Repository: https://github.com/skorokithakis/shortuuid
Related repositories
Similar repositories that may be relevant next.
awesome-slugify: A Flexible Python Slugify Function
July 31, 2026
awesome-slugify is a powerful and flexible Python library designed for converting text into clean, URL-friendly slugs. It offers extensive customization options, including separators, case conversion, and length limits. The library also supports unique slug generation and comes with predefined configurations for various languages and use cases.
hashids-python: Generate YouTube-like Hashes from Numbers
July 31, 2026
`hashids-python` is a Python implementation of the `hashids` library, designed to generate short, unique, YouTube-like hashes from one or many numbers. It's ideal for obfuscating database IDs without exposing their original values to users. This library ensures compatibility across Python 2 and 3, offering a flexible way to handle public-facing identifiers.

PLY: A Legacy Python Lex-Yacc Parser Generator (Project Abandoned)
July 30, 2026
PLY (Python Lex-Yacc) is a zero-dependency Python implementation of the traditional lex and yacc parsing tools, designed for building compilers, ASTs, and protocol decoders. Created by David Beazley, it offers a robust LALR(1) parsing algorithm compatible with modern Python versions. However, it's important to note that the project has been officially abandoned by its author, with no further maintenance expected.

python-phonenumbers: Google's libphonenumber Port for Python
July 30, 2026
`python-phonenumbers` is a robust Python port of Google's highly acclaimed `libphonenumber` library. It offers comprehensive functionality for parsing, validating, and formatting international phone numbers, making it an indispensable tool for global applications. This library ensures accurate and standardized phone number handling across diverse regions.
Source repository
Open the original repository on GitHub.