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)
  • FastAPI support (just use Pydantic as you want)
  • 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

class UserUUID(PUUIDv7[Literal["user"]]): ...

# Generation
uid = UserUUID.factory()
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-2.0.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

puuid-2.0.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: puuid-2.0.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for puuid-2.0.0.tar.gz
Algorithm Hash digest
SHA256 622b5f0f7844d705983794d446d4b0b860c62e3c8b377832b343db5260384393
MD5 68fec9b592da83ec5b51e5686ea7c25f
BLAKE2b-256 2fef53fb6747b7e88ee96ebdcabdfbbb3acbb4e3775d3b8ccce6bafa6aeeb9b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: puuid-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for puuid-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 639bed4929e8b1cc4af96cf9114e1a270983f2426929c3176152c336c867e943
MD5 65254299bc602658c71fb70eb29cac86
BLAKE2b-256 cb5d2eb318ef85165dd2cb1b4ce847e1e4379a5e60776675d221b9b24762199c

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