Skip to main content

Prefixed UUIDs for Python with Pydantic & SQLAlchemy support.

Project description

Logo: pUUID - Prefixed UUIDs for Python

pUUID - Prefixed UUIDs for Python with Pydantic & SQLAlchemy support.

repository mirror License: LGPLv3 pipeline status coverage report Code style: black Imports: isort

pkgversion versionsupport Downloads Week Downloads Total


pUUID - Prefixed UUIDs for Python

Raw UUIDs like 019b9a2e-9856-... are annoying to work with. They provide no context in logs, traces or bug reports and offer no safe guards against accidental ID swapping in code. pUUID provides prefixed UUIDs for python with minimal overhead and strong type guarantees.

Features

  • Human-Friendly: Immediate context with prefixed UUIDs (e.g. user_019b9a2e...).
  • Strong type guarantees: Prevent passing of a CustomerID into a payment_id field.
  • Standard Compliant: Supports all UUID versions from RFC 9562.
  • Pydantic support. (Read more)
  • SQLAlchemy support. (Read more)

Installation

# NOTE: pUUID requires python 3.14+
pip install pUUID

# For Pydantic support:
pip install 'pUUID[pydantic]'

# For SQLAlchemy support:
pip install 'pUUID[sqlalchemy]'

Usage

Define a domain-specific ID by inheriting from a versioned base:

from typing import Literal
from puuid import PUUIDv7

UserUUID = PUUIDv7[Literal["user"]]

# Generation
uid = UserUUID()
print(uid) # user_019b956e-ed25-70db-9d0a-0f30fb9047c2

# Deserialization
uid2 = UserUUID.from_string("user_019b956e-ed25-70db-9d0a-0f30fb9047c2")

Resources

Alternatives

If you only need lexicographically sortable IDs and want to build the SQLAlchemy support yourself, these two projects might be for you:

  • TypeID - pUUID supports all UUID versions because it uses Python’s standard uuid library for UUID generation, while TypeID uses a custom generator that comes with performance improvements but only supports UUIDv7. TypeID does not support SQLAlchemy out of the box.
  • UPID - UPID implements a modified version of the ULID standard, which was designed before UUIDv7 was available. UPID does not support SQLAlchemy out of the box.

Sponsor

Digon.IO GmbH Logo

Digon.IO provides dev & data end-to-end consulting for SMEs and software companies. (Website) (Technical Blog)

The sponsor logo is the property of Digon.IO GmbH. Standard trademark and copyright restrictions apply to any use outside this repository.

License

  • Library source code: Licensed under LGPLv3.

Project details


Download files

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

Source Distribution

puuid-1.2.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

puuid-1.2.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file puuid-1.2.0.tar.gz.

File metadata

  • Download URL: puuid-1.2.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.8

File hashes

Hashes for puuid-1.2.0.tar.gz
Algorithm Hash digest
SHA256 8c8ca594f7636722ca1b3f39feddca22e68cd6eb068ba5621f147ca9d5ca6acf
MD5 1193ba4d50beefb4cbae4760c140c704
BLAKE2b-256 7051b60495826b039ee9c53d02b9ecddfc9b7666c9448cdc3ed2dacb02405968

See more details on using hashes here.

File details

Details for the file puuid-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: puuid-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.8

File hashes

Hashes for puuid-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 208e3a0ee41d444010227dd345c364c4780b3661c7572d40ba9622a199099c3a
MD5 ee9ff85e1e902ee60217fb230c826222
BLAKE2b-256 b0ab503f805f96e58ca223747c49316b6d036f2bf8a71b43216e1948dcbfe870

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page