Prefixed UUIDs for Python with Pydantic & SQLAlchemy support.
Project description
pUUID - Prefixed UUIDs for Python with Pydantic & SQLAlchemy support.
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
CustomerIDinto apayment_idfield. - 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
uuidlibrary 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 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file puuid-1.1.0.tar.gz.
File metadata
- Download URL: puuid-1.1.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fb88174730a7f7cb1fa8ae6511437d0639113696745b67f2b1642768cf9fb42
|
|
| MD5 |
662a230c603a2d7bfad23759b5a3f319
|
|
| BLAKE2b-256 |
c91e58fc0e16ec3cebb19459ca247fe2a24409f6732d81c76f842e13b72ed53c
|
File details
Details for the file puuid-1.1.0-py3-none-any.whl.
File metadata
- Download URL: puuid-1.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0f8f96af9d6b8c70d876e4ef3a6254194079d3dcf6b20319e233debb03bcd48
|
|
| MD5 |
2a1703432f474d328cef3f8fa35d3537
|
|
| BLAKE2b-256 |
093045ed5f93149e2bd75045b032cd558c4458c15d7f206d91c686ae9f5e9795
|