skillfed

python-ulid

Universally unique lexicographically sortable identifier

python-ulid v4.0.1 10.1M downloads/30d#1,477 on PyPI566
Permissive license MIT Active released

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-ulid

uv

uv add python-ulid

poetry

poetry add python-ulid

Installing 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

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: MacOS :: MacOS XOperating System :: POSIX :: LinuxProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Software Development :: Libraries

Tags

ULID generatorsortable unique identifierUUID alternativetimestamp-based IDdistributed ID generationlexicographic sorting identifierbase32 encoded ID
identifier-generationdatabase-keysdistributed-systems

More Libraries packages