Skip to main content

UUIDv7 for Python

A simple module for generating UUIDv7s with creation times, and for extracting the time from a UUID.

ℹ️ At the time of writing, Python had no UUIDv7 support. It does now, but still doesn't allow providing or extracting timestamps, which we do. Beware that there is also an abandoned package named uuid7 that uses a draft RFC and produces all wrong timestamps.

  • Standards-compliant: Follows the final UUIDv7 specification.
  • Pythonic: Uses stdlib datetime and UUID facilities rather than (milli)seconds, custom UUID types, or bare strings, as used by alternatives such as uuid7-rs.
  • Lightweight: A tiny pure-Python module with no dependencies, fast enough to process about a million UUIDv7s per second per CPU core.

Installation

pip install uuid7-standard

Or, add to your project using uv:

uv add uuid7-standard

Usage

import uuid7
from datetime import datetime, UTC
from uuid import UUID

# Create a random UUIDv7 with the current timestamp, same as uuid.uuid7()
u = uuid7.create()
print(str(u), u.bytes)

# Create one with a specific timestamp
when = datetime(1970, 1, 1, tzinfo=UTC)
u = uuid7.create(when)

# Extract the timestamp
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 a datetime (local time or timezone-aware). This is useful for creating multiple UUIDv7s 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

Useful when you want to indicate explicitly that a value is expected to be UUIDv7 while avoiding a separate import uuid.

Note that uuid7.UUID is uuid.UUID and does not enforce the UUIDv7 format. It does, however, help humans and coding agents avoid accidentally using uuid4() when working with such values.

Metadata

Release files for uuid7-standard 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for uuid7-standard 1.1.2
File Size Uploaded Provenance Actions
uuid7_standard-1.1.2.tar.gz 2.4 kB Without provenance Details for uuid7_standard-1.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for uuid7-standard 1.1.2
File Interpreter ABI Platform Actions
uuid7_standard-1.1.2-py3-none-any.whl Python 3 none any Details for uuid7_standard-1.1.2-py3-none-any.whl

Total release size: 5.2 kB

Release files / uuid7_standard-1.1.2.tar.gz

Download URL uuid7_standard-1.1.2.tar.gz
Size 2.4 kB
Tags Source
SHA-256 checksum
How to use checksums
14cf739a37a1e6e85cff4c7460bd3f6bf4c48c1e44ce19a0857b08e172352c26
BLAKE2b-256 checksum
How to use checksums
59d4434537cb478e2b8e5aa47c93ca6a8cb744fa05331fa1c3979e5d08666743
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / uuid7_standard-1.1.2-py3-none-any.whl

Download URL uuid7_standard-1.1.2-py3-none-any.whl
Size 2.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa1520e9d2fb51cba45073e20d7ca56812c46e0f38848eaa2f6cd530368522d3
BLAKE2b-256 checksum
How to use checksums
e1414495f1228e298d656340c39d3aa4ceac54edb923d728210e79f4c329fa5c
Upload date
Uploaded using Trusted Publishing?
What is 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}

Security for uuid7-standard 1.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page