Python uuid Module
Example
Generate a random UUID:
import uuid
id1 = uuid.uuid4()
id2 = uuid.uuid4()
print(f'UUID 1: {id1}')
print(f'UUID 2: {id2}')
print(f'Are they equal? {id1 == id2}')
Try it Yourself »
Definition and Usage
The uuid module generates universally unique identifiers (UUIDs) according to RFC 4122.
Use it to create unique identifiers for database records, session IDs, or distributed systems.
Members
Member | Description |
---|---|
UUID | Class representing a UUID. |
getnode() | Get hardware address as a 48-bit positive integer. |
uuid1() | Generate UUID based on host ID and current time. |
uuid3() | Generate UUID based on MD5 hash of namespace and name. |
uuid4() | Generate random UUID. |
uuid5() | Generate UUID based on SHA-1 hash of namespace and name. |