Skip to main content

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 datetime and UUID facilities 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uuid7_standard-1.1.0.tar.gz (2.2 kB view details)

Uploaded Source

Built Distribution

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

uuid7_standard-1.1.0-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

Details for the file uuid7_standard-1.1.0.tar.gz.

File metadata

  • Download URL: uuid7_standard-1.1.0.tar.gz
  • Upload date:
  • Size: 2.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.12

File hashes

Hashes for uuid7_standard-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c7efdef8309265444fd11439bda8df10bd6469b56be62c1d3d78e014d16b4b9a
MD5 e331b5ed9860c010aa0c7724356f5102
BLAKE2b-256 700dbbb440a1fad38c1be8cdc4c379e061ec10661061e43b68cf7e9ae718455b

See more details on using hashes here.

File details

Details for the file uuid7_standard-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for uuid7_standard-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 725f8f9202662dd6212df6b8caa1e101c2a61935261f43438bca842e058c5726
MD5 219305fe5751ef96b4c4dea0c561d35d
BLAKE2b-256 1a3e568b8382627e0fec58ef3c83c3cafa241b86ff41ba37874df057693c12d1

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