uuid.uuid1
The timestamp counts 100-nanosecond steps since 1582-10-15; node defaults to getnode(), the hardware address; clock_seq defaults to 14 random bits. The docs warn that uuid1 "may compromise privacy" because of that address.
Demo
import uuid u = uuid.uuid1(node=20015998343868, clock_seq=4660) (hex(u.node), u.clock_seq, u.version, u.variant)
clock_seq is masked to 14 bits: 20000 becomes 3616 and -1 becomes 16383 (Python's & works on negative ints as if they had infinitely many 1 bits). node is not masked on 3.13: 2**48 fails the 48-bit check of UUID(fields=...). The timestamp is not shown because it changes with every call.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| node | int | None | no (None) | The 48-bit node; None means getnode(). On 3.13 a value of 2**48 or more raises ValueError. |
| clock_seq | int | None | no (None) | The sequence number; only its low 14 bits are used. None means random.getrandbits(14). |
Return value
uuid.UUID — A version 1 UUID: 60-bit timestamp, 14-bit clock sequence, 48-bit node.
Common patterns
import random, uuid node = random.getrandbits(48) | (1 << 40) u = uuid.uuid1(node=node)
import uuid from datetime import datetime, timedelta made = datetime(1582, 10, 15) + timedelta(microseconds=u.time // 10)
Examples
Pitfalls
import uuid uuid.uuid1().node == uuid.getnode()
import uuid uuid.uuid4().version
import uuid early = uuid.UUID(fields=(0xffffffff, 0, 0x1000, 0x80, 0, 1)) late = uuid.UUID(fields=(0, 1, 0x1000, 0x80, 0, 1)) sorted([late, early])[0] == early
import uuid early = uuid.UUID(fields=(0xffffffff, 0, 0x1000, 0x80, 0, 1)) late = uuid.UUID(fields=(0, 1, 0x1000, 0x80, 0, 1)) sorted([late, early], key=lambda u: u.time)[0] == early
When to use
- Legacy systems that expect version 1 UUIDs
- Internal IDs where the embedded time is useful and the address is not a concern
- Public or user-facing IDs → uuid4 (no address, no time)
- Database keys that must sort by time → u.time is not the sort order of UUIDs; 3.14 adds uuid6/uuid7 for that
Notes
FAQ
Yes, by default: node is getnode(), the hardware address of a network interface (or a random number with the multicast bit set if none is found). Pass node= to avoid it, or use uuid4.