Python UUID Versions 6, 7, and 8

Python 3.14 adds support for UUID versions 6, 7, and 8 in the standard uuid module. These formats come from RFC 9562 and complement the older UUID versions already available in Python.

Create UUID Version 6

Example:

import uuid

value = uuid.uuid6()
print(value)
print(value.version)

UUID version 6 rearranges time-based UUID data so values sort more naturally by creation time than version 1 UUIDs.

Create UUID Version 7

Example:

import uuid

value = uuid.uuid7()

print(value)
print(value.version)
print(value.time)

For UUID version 7, value.time is a Unix timestamp in milliseconds. The identifier can be sorted approximately by creation time, but it also exposes timing information.

Create UUID Version 8

Example:

import uuid

value = uuid.uuid8()
print(value)
print(value.version)

UUID version 8 is intended for application-defined layouts while keeping the UUID variant and version structure.

Choose the Right Version

Version Typical reason to use it
6 Time-based ordering with a layout better suited to sorting
7 Timestamp-based identifiers with good sort behavior
8 Application-specific UUID layouts

Command-Line Generation

Python 3.14 also lets the uuid module generate these versions from the command line.

Example:

python -m uuid -u uuid7

UUIDs Are Still Not Sequential Integers

Time-ordered UUIDs improve locality and sorting, but they are still 128-bit identifiers. Do not assume that two nearby UUIDs were created by the same process or that every timestamp sequence is gap-free.

Use UUID version 7 when you need a modern, time-sortable identifier and do not specifically require the node and clock semantics of older time-based UUIDs.

UUIDs are identifiers, not secret access tokens. The default randomness of uuid8() is not cryptographically secure. Use secrets for reset tokens or API secrets. Version 6 can include a node identifier derived from a hardware address.

Conclusion

Python 3.14 makes UUID versions 6, 7, and 8 directly available through the standard library. Version 7 is especially useful for systems that want globally unique identifiers with creation-time ordering.



Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram