How to Create a GUID/UUID in Python

Created
Modified

Using uuid Module

uuid module provides immutable UUID objects (the UUID class) and the functions uuid1(), uuid3(), uuid4(), uuid5() for generating version 1, 3, 4, and 5 UUIDs as specified in RFC 4122.

See the following example:

#!/usr/bin/python3

# Import module
import uuid

print(uuid.uuid4())

# a 32-character hexadecimal string
print(uuid.uuid4().hex)
a41324c5-fff7-48c8-b7a5-75b4ed877ad9
9606b3e9a271426e8790d72cd90882a4

Related Tags

#create# #uuid#