GUID V4 - Random-Based Identifier (Recommended)
GUID v4 is the most widely used random-based identifier. Learn about its structure, collision probability, advantages and why it is recommended for general-purpose applications.
Generate UUIDs in Python with the standard uuid module for v4 and with uuid.uuid7() on Python 3.14 or newer, then convert between UUID objects and strings with str() and uuid.UUID(...).
import uuid
id = uuid.uuid4()
print(id)Python 3.14 added uuid.uuid7(). On older versions, use a compatibility package that implements RFC 9562.
import uuid
id = uuid.uuid7()
print(id)import uuid
id = uuid.uuid4()
uuid_text = str(id)
uuid_hex = id.hex
print(uuid_text)
print(uuid_hex)import uuid
value = "550e8400-e29b-41d4-a716-446655440000"
parsed = uuid.UUID(value)
print(parsed)
print(parsed.version)str(uuidValue) to get the canonical dashed string form, and use uuid.UUID(text) to parse the string back into a UUID object.uuid.uuid7() is native starting in Python 3.14. Use a UUID compatibility library or keep using v4 until your deployment target reaches that version.These articles expand on related concepts, formats and practical considerations.