On this page
uuid.uuid7
Prev: uuid.uuid6 | Up: uuid | Next: uuid.uuid8
Rel: uuid.bytes_, uuid.Enum, uuid.getnode, uuid.int_
Ref: docs.python.org — uuid.uuid7
Tags: #public #python3 #stdlib #uuid
Import
import uuid
from uuid import uuid7
Signature & Overview
uuid.uuid7()
Generate a UUID from a Unix timestamp in milliseconds and random bits.
Usage
import uuid
if hasattr(uuid, 'uuid7'):
u1, u2 = uuid.uuid7(), uuid.uuid7()
assert u1.version == 7 and u1 <= u2
Gotchas
- Requires Python 3.14+ (RFC 9562): Monotonically sortable millisecond-timestamp + random UUID—ideal for database primary keys.
REPL Inspect
from uuid import uuid7
help(uuid7)
Linked from
Related notes
- tuts/python3/stdlib_module/uuid/uuid6 Linked here; links to this page; shared tags: #stdlib, #uuid
- tuts/python3/stdlib_module/uuid/uuid8 Linked here; links to this page; shared tags: #stdlib, #uuid
- tuts/python3/stdlib_module/uuid/bytes_ Linked here; shared tags: #stdlib, #uuid
- tuts/python3/stdlib_module/uuid/Enum Linked here; shared tags: #stdlib, #uuid
- tuts/python3/stdlib_module/uuid/getnode Linked here; shared tags: #stdlib, #uuid
- tuts/python3/stdlib_module/uuid/int_ Linked here; shared tags: #stdlib, #uuid
- tuts/python3/stdlib_module/uuid/UUID Linked here; shared tags: #stdlib, #uuid
- tuts/python3/stdlib_module/uuid links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/uuid/main shared tags: #stdlib, #uuid
- tuts/python3/stdlib_module/uuid/SafeUUID shared tags: #stdlib, #uuid