python-ulid
Universally unique lexicographically sortable identifier
What it is and what it does
python-ulid is a library for creating and working with ULIDs, a 128-bit identifier format that combines a 48-bit millisecond timestamp with 80 bits of randomness. Unlike UUIDs, ULIDs are lexicographically sortable, meaning they sort correctly by creation time without additional logic. They encode to a compact 26-character base32 string (versus UUID's 36 characters) and are URL-safe with no special characters.
The library provides multiple ways to generate ULIDs (from current time, from a specific timestamp, from a datetime object), convert them to various formats (string, hex, int, bytes, UUID), and extract the timestamp component. It includes customizable monotonicity policies to handle collisions when multiple ULIDs are generated within the same millisecond, optional Pydantic integration for data validation, and a command-line interface for generating and inspecting ULIDs.
Use it for:
- Generate sortable primary keys for database records that preserve insertion order without a separate sequence.
- Create distributed IDs across multiple services without coordination, using timestamp + randomness to avoid collisions.
- Replace UUIDs in APIs and URLs where a shorter, more readable identifier is preferred.
- Build audit logs or event streams where IDs must be both unique and sortable by time.
- Validate ULID strings in Pydantic models for API request/response schemas.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Generates and manipulates ULIDs (universally unique lexicographically sortable identifiers)—128-bit identifiers that are sortable by timestamp, more compact than UUIDs, and suitable for database keys and distributed systems.
Yes. The package is actively maintained, has no known vulnerabilities, installs with minimal friction (one lightweight dependency), supports current Python versions (3.10–3.14), and solves a real problem for applications needing sortable unique identifiers. Use it whenever you need UUIDs but want sortability and compactness.
Install
python-ulid on PyPI
pip
pip install python-uliduv
uv add python-ulidpoetry
poetry add python-ulidInstalling python-ulid
Before you install
Low friction: pure Python wheel with only typing-extensions as a runtime dependency. Active maintenance with a release 25 days ago and recent commits.
License in practice
MIT license (permissive): you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install python-ulid
from ulid import ULID
ulid = ULID()
print(str(ulid)) # e.g., '01BTGNYV6HRNK8K8VKZASZCFPE'
print(ulid.datetime) # extract timestamp as datetime
Requires Python 3.10 or later.
Verify before relying
- Performance characteristics under high-throughput generation (monotonicity policy overhead not quantified).
- Whether Pydantic integration requires the optional pydantic extra or works with core install.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — typing-extensions |
| Maintenance | actively maintained — 25 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 10,132,513/month — #1,477 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: python_ulid-4.0.1-py3-none-any.whl
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
py-deviceidGenerates or retrieves a unique device…
permissive · top 5,000 on PyPI
ulidGenerates ULIDs (Universally Unique…
permissive · top 15,000 on PyPI
ulid-pyGenerates and parses ULIDs (Universally Unique…
permissive · top 5,000 on PyPI
timeflakeGenerates 128-bit, time-ordered, URL-safe…
permissive · top 15,000 on PyPI
ulid-transformGenerate and convert ULIDs (Universally Unique…
permissive · top 15,000 on PyPI
uuid-extensionGenerates UUID version 7…
unclear · top 15,000 on PyPI
uuid-v7Generates UUID v7 and v6 identifiers, extending…
unclear · top 15,000 on PyPI
ksuidGenerates sortable unique identifiers (KSUIDs)…
permissive · top 15,000 on PyPI
uuid-utilsFast UUID generation and manipulation for all…
permissive · top 1,000 on PyPI
typeid-pythonGenerates and parses TypeIDs—type-safe,…
permissive · top 15,000 on PyPI