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
Metadata
Release files for uuid-extension 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| uuid_extension-0.2.0.tar.gz | 54.5 kB | Without provenance | Details for uuid_extension-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| uuid_extension-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for uuid_extension-0.2.0-py3-none-any.whl |
Total release size: 60.1 kB
Release files / uuid_extension-0.2.0.tar.gz
| Download URL | uuid_extension-0.2.0.tar.gz |
|---|---|
| Size | 54.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e68907184276f47a4b169dc9891477693371b5f3756aebdaffb7cf83b9a6077e
|
|
BLAKE2b-256 checksum How to use checksums |
054e55636e6655feae1e843e5db0255edb42497e1fb865529860a916e82286d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.2
|
Release files / uuid_extension-0.2.0-py3-none-any.whl
| Download URL | uuid_extension-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8dac0d934afd07a16ae8537dd873bc833f1fcc31530295029d86c9cea49bf6a3
|
|
BLAKE2b-256 checksum How to use checksums |
4382006fbeb46fc6856ea813c4a09264c2fd60dc86e6c19b218b31b17766cba9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.2
|
Security for uuid-extension 0.2.0
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.