UUIDv7 with the final standard. Not to be confused with the uuid7 package on pypi, based on a draft version that was very different.
Project description
UUIDv7 for Python
A simple module for generating UUIDv7 that contain creation timestamps. Another function for extracting the time of an UUID.
Note: As of writing, Python has no UUIDv7 support. There's an abandoned package uuid7 that uses a draft RFC with incorrect timestamps (some two centuries off). These modules conflict, uninstall the other one.
- Standard compliant: Follows the final UUIDv7 specification.
- Pythonic: Uses stdlib
datetimeandUUIDfacilities rather than milliseconds or bare strings.
Installation
pip install uuid7-standard
Or for your project using uv:
uv add uuid7-standard
Usage
import uuid7
# Create a random UUIDv7 with current timestamp
u = uuid7.create()
print(str(u), u.bytes)
# Create with specific timestamp
from datetime import datetime, UTC
when = datetime(1970, 1, 1, tzinfo=UTC)
u = uuid7.create(when)
# Extract timestamp
from uuid import UUID
u = UUID('00000000-0000-7dac-b3e3-ecb571bb3e2f')
timestamp = uuid7.time(u) # 1970-01-01 UTC
create(when: datetime?) -> UUID
Create a UUIDv7 with timestamp-based ordering.
The current time is used, unless when is passed as datetime (local time or timezone-aware) This is useful e.g. for creating a bunch of UUIDv7 with precisely the same timestamp.
time(u: UUID|str) -> datetime
Extract the timestamp from a UUIDv7. Raises ValueError if the UUID is not a UUIDv7.
Project details
Release history Release notifications | RSS feed
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 uuid7_standard-1.0.0.tar.gz.
File metadata
- Download URL: uuid7_standard-1.0.0.tar.gz
- Upload date:
- Size: 2.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f077a0ce8403532d258a5f1536807f4082713078f513db958c2f7e6e3df644e2
|
|
| MD5 |
8ef478ef700fb34f249dda2eeee24601
|
|
| BLAKE2b-256 |
eb97a9d99386997c3a2f22aea36f2bbd23b362a7c89b1fbf02474c4f7875df9a
|
File details
Details for the file uuid7_standard-1.0.0-py3-none-any.whl.
File metadata
- Download URL: uuid7_standard-1.0.0-py3-none-any.whl
- Upload date:
- Size: 2.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9cfb6eff96d87212e40038f07eece54ba1ded23a466477626b428f99e608433a
|
|
| MD5 |
65d19696584dcdb8b83d4941ee7a6946
|
|
| BLAKE2b-256 |
df917232e5e494e6a357ceeb7356589c29946e9c325ebcc36f56b0617df140ec
|