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

Metadata

Release files for larzuuid 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for larzuuid 0.1.0
File Size Uploaded Provenance
larzuuid-0.1.0.tar.gz 5.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for larzuuid 0.1.0
File Interpreter ABI Platform
larzuuid-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.5 kB

Release files / larzuuid-0.1.0.tar.gz

Download URL larzuuid-0.1.0.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e952f36a22148270dc160202d97e7e4903e362a6533a5f767486da67bdcf949b
BLAKE2b-256 checksum
How to use checksums
f21fa3eb8cdb177616521fc8630ca6f32e36fedb65b363b7f6c1de2c7bb7c5de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / larzuuid-0.1.0-py3-none-any.whl

Download URL larzuuid-0.1.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
19cdd0b38e047f42e36f9dce95e44925c43bb3bbf3a9359ce1cfe75cf3d6d109
BLAKE2b-256 checksum
How to use checksums
4692f0360ff391fc050a52a3676eaa83fa71dff115c0aab5b449be541b94b96f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Security for larzuuid 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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