UUID6
The uuid6 library provides new time-based UUID formats (v6, v7, v8) that are optimized for use as database keys, offering better performance and sequential ordering than traditional UUIDv1. As of version 2025.0.0, the project transitioned from Calendar Versioning (YYYY.MM.DD) to Semantic Versioning (MAJOR.MINOR.PATCH) and maintains a frequent release cadence.
Warnings
- breaking Beginning with version 2025.0.0, the project transitioned from Calendar Versioning (YYYY.MM.DD) to Semantic Versioning (MAJOR.MINOR.PATCH). This impacts how future versions are declared and may require adjustments in dependency pinning strategies.
- breaking Support for Python 3.8 was dropped in version 2025.0.0. Earlier, Python 3.7 support was removed in 2023.04.25. The library now requires Python 3.9 or newer.
- breaking In version 2022.10.25, the internal timestamp granularity for `uuid7()` was changed from nanoseconds to milliseconds, aligning with Draft 00 of the RFC. This significantly alters the uniqueness characteristics and ordering guarantees if you were relying on nanosecond precision.
- gotcha `uuid8()` is provided for custom, user-defined UUIDs as per RFC 9562, often requiring specific byte sequences or fields. It's not a direct drop-in replacement for the older nanosecond-granularity `uuid7()` behavior and requires careful implementation for specific use cases.
Install
-
pip install uuid6
Imports
- uuid6
from uuid6 import uuid6
- uuid7
from uuid6 import uuid7
- uuid8
from uuid6 import uuid8
- UUID
from uuid6 import UUID
- uuid1_to_uuid6
from uuid6 import uuid1_to_uuid6
Quickstart
from uuid6 import uuid6, uuid7, UUID
# Generate a UUIDv6
my_uuid6 = uuid6()
print(f"Generated UUIDv6: {my_uuid6}")
print(f"Type: {type(my_uuid6)}")
# Generate a UUIDv7 (millisecond granularity)
my_uuid7 = uuid7()
print(f"Generated UUIDv7: {my_uuid7}")
# You can also instantiate UUID objects from strings
uuid_obj = UUID("018e612f-8700-613d-88f5-93717d2f9d6c")
print(f"UUID object from string: {uuid_obj}")