Skip to main content

UUID Extension for Python

Project description

UUID Extension for Python

A Python library implementing UUID version 7 as specified in the RFC, providing time-ordered UUIDs for modern applications.

Features

  • Full implementation of UUID version 7
  • Time-ordered UUIDs for better database performance
  • Compatible with standard Python UUID objects
  • Timestamp extraction capabilities
  • Optional counter for monotonicity within milliseconds

Installation

pip install uuid-extension

Usage

Basic Usage

from uuid_extension import uuid7

# Generate a new UUID7
uuid = uuid7()
print(uuid)  # e.g., 018c1585-5e7c-7601-b322-5bf9f7478708

# Access the underlying UUID object
uuid_obj = uuid.uuid7

With Timestamp

from datetime import datetime
from uuid_extension import uuid7

# Generate UUID7 with a specific timestamp
custom_time = datetime.now()
uuid = uuid7(timestamp=custom_time)

# Or with Unix timestamp
uuid = uuid7(timestamp=1690000000.123)

With Counter

from uuid_extension import uuid7

# Use a counter for guaranteeing monotonicity within the same millisecond
counter = 1
id1 = uuid7(counter=counter)
counter += 1
id2 = uuid7(counter=counter)

Time Extraction

from uuid_extension import uuid7

uuid = uuid7()

# Extract timestamp as float (Unix timestamp in seconds)
ts = uuid.to_timestamp()

# Extract as datetime object (UTC timezone by default)
dt = uuid.to_datetime()

# Extract as datetime with a specific timezone
import pytz
dt_est = uuid.to_datetime(tz=pytz.timezone('US/Eastern'))

Comparison Operations

UUID7 objects support standard comparison operations:

id1 = uuid7()
id2 = uuid7()

print(id1 == id2)  # False
print(id1 < id2)   # True (usually, as they're time-ordered)
print(id1 <= id2)  # True

Technical Details

UUID version 7 structure:

  • 48 bits of Unix timestamp in milliseconds
  • 4 bits for version (set to 7)
  • 2 bits for variant (set to 0b10)
  • 74 bits of random data for uniqueness

License

MIT License

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

uuid_extension-0.0.4.tar.gz (56.3 kB view details)

Uploaded Source

Built Distribution

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

uuid_extension-0.0.4-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file uuid_extension-0.0.4.tar.gz.

File metadata

  • Download URL: uuid_extension-0.0.4.tar.gz
  • Upload date:
  • Size: 56.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.2

File hashes

Hashes for uuid_extension-0.0.4.tar.gz
Algorithm Hash digest
SHA256 30af0a473c75872304ee02c2089d0bb28b0bea5f3aeaf8bfc69d4ecc413f9231
MD5 bfee089c5e9ef34bb29bbee08d341b06
BLAKE2b-256 306b56c9b4b99dda673e64230e554d06b86f2c314a3e01d78cbf2ca9eb0ad932

See more details on using hashes here.

File details

Details for the file uuid_extension-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for uuid_extension-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e32f40a3190e3292f83db15f80dc0c1ce8c4362cb34b505edd6a9d0e75727aa6
MD5 ee948234928c20223c3dc12c2df775c2
BLAKE2b-256 3af6bf6d59fd248442ad9143da832c9606f68b161e24c08d2cb2dedb683ec4f9

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