Skip to main content

larzuuid

Modern, sortable IDs — UUIDv7, ULID, nanoid. Pure Python, zero dependencies.

Random UUIDv4s are unguessable but scatter across a database index, hurting insert performance and locality. Time-ordered ids fix that: they sort by creation time, cluster in the index, and let you read the timestamp back out. The stdlib uuid module has none of these — larzuuid adds the three you actually want.

from larzuuid import uuid7, ulid, nanoid

uuid7()     # 018f5e...-7...  a real UUID, but time-sortable
ulid()      # 01HZY3K5...     26-char Crockford base32, sortable
nanoid()    # V1StGXR8_Z5jdHi6B-myT   compact, URL-safe

Why

  • UUIDv7 (RFC 9562) — a standard uuid.UUID, but the first 48 bits are a millisecond timestamp, so it sorts by time and works as a great primary key. Read the time back with uuid7_timestamp().
  • ULID — 26 lexicographically-sortable Crockford-base32 chars; MonotonicULID guarantees strictly increasing ids even within the same millisecond.
  • nanoid — a compact, URL-safe random id (21 chars by default), uniform via rejection sampling, with a custom alphabet option.
  • Zero dependencies. No ulid-py, no nanoid, no uuid6.

Install

pip install larzuuid

Usage

from larzuuid import uuid7, uuid7_timestamp, ulid, ulid_timestamp, MonotonicULID, nanoid

pk = uuid7()                       # use as a DB key; sorts by creation time
uuid7_timestamp(pk)                # datetime (UTC)

u = ulid(); ulid_timestamp(u)
gen = MonotonicULID(); gen.new(); gen.new()   # strictly increasing

nanoid()          # 21 chars
nanoid(10, alphabet="0123456789abcdef")

Tests

python -m unittest discover -s tests -v   # 13 tests

The Larz stack

One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter.

License

MIT © larz-scripter

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

larzuuid-0.1.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

larzuuid-0.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file larzuuid-0.1.0.tar.gz.

File metadata

  • Download URL: larzuuid-0.1.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzuuid-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e952f36a22148270dc160202d97e7e4903e362a6533a5f767486da67bdcf949b
MD5 ec106f184fa2590b650b78df15033c5e
BLAKE2b-256 f21fa3eb8cdb177616521fc8630ca6f32e36fedb65b363b7f6c1de2c7bb7c5de

See more details on using hashes here.

File details

Details for the file larzuuid-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: larzuuid-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzuuid-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 19cdd0b38e047f42e36f9dce95e44925c43bb3bbf3a9359ce1cfe75cf3d6d109
MD5 63dc18292745bbeaf96fab125bbc4269
BLAKE2b-256 4692f0360ff391fc050a52a3676eaa83fa71dff115c0aab5b449be541b94b96f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page