all Python 3uuidterm
uuid
module
Creates and parses UUIDs, universally unique identifiers: random, name-based and time-based.
Syntax
import uuid
For a random record or file identifier use uuid4(); uuid5() gives the same UUID for the same name, and uuid7() from Python 3.14 is time-ordered and handy as a database key. uuid1() reveals the machine's MAC address, so it is avoided for public identifiers. A UUID is not a secret: tokens and passwords need the secrets module.
Examples
import uuid
u = uuid.uuid4()
print(u) # → ? случайный, вида 1b4e28ba-2fa1-4d3b-a3f5-ef19b5a7633b
print(u.version, len(str(u))) # → 4 36
print(uuid.uuid5(uuid.NAMESPACE_DNS, "python.org")) # → 886313e1-3b8a-5372-9b90-0c9aee199e5d
See also
Open in the full glossarydocs.python.orgReport an inaccuracy