UUIDv7 for Python
A simple module for generating UUIDv7 that contain creation timestamps. Another function for extracting the time of an UUID.
ℹ️ As of writing, Python had no UUIDv7 support. Now it does, but doesn't allow providing nor extracting timestamps, which both are supported by this module. Beware there's also an abandoned package uuid7 that uses a draft RFC with incorrect timestamps (some two centuries off).
- 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, same as uuid.uuid7()
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
uuid7.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.
uuid7.time(u: UUID|str) -> datetime
Extract the timestamp from a UUIDv7. Raises ValueError if the UUID is not a UUIDv7.
uuid7.UUID re-export of stdlib UUID
In case you wish to explicitly indicate in your code that something is supposed to be v7, and avoid import uuid. Note that it is uuid.UUID, and does not actually enforce v7 format. This is useful with humans and coding agents, to avoid them accidentally using uuid4() when dealing with it.
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.1.1.tar.gz.
File metadata
- Download URL: uuid7_standard-1.1.1.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e981c2f5f4126be06b4e1d88b9b6f7f57f5e3f2f1a98fa85418da6f47ff8cb81
|
|
| MD5 |
62521f67625192d04ee62f5016905baa
|
|
| BLAKE2b-256 |
4301141c3c12c3c43911adc0d008e795eab449d47c3bcbed10b6a418822327aa
|
File details
Details for the file uuid7_standard-1.1.1-py3-none-any.whl.
File metadata
- Download URL: uuid7_standard-1.1.1-py3-none-any.whl
- Upload date:
- Size: 2.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cab10c2b1117b61603e352e2741f36a2c6b8a7406038586631690716483ef5c
|
|
| MD5 |
42ccec45b51788d78e2fd27f0d59f9b2
|
|
| BLAKE2b-256 |
2f95d22f4c4cb13fefad7c62e18b6cb273cf09afd9a6384ade4c115f9e02a788
|