Python
Its easy to make GUIDs in Python. The built-in uuid module (Python 2.5+) provides
cryptographically secure UUID generation that conforms to RFC 4122.
Standard Method (Python 2.5+)
import uuid
# Generate a random UUID (version 4)
my_uuid = uuid.uuid4()
print(my_uuid) # e.g., "f47ac10b-58cc-4372-a567-0e02b2c3d479"
# Get as string
uuid_string = str(my_uuid)
print(uuid_string)
Other UUID Versions
Python's uuid module supports multiple UUID versions:
import uuid
# UUID1: Based on host ID and current time
uuid1 = uuid.uuid1()
print(f"UUID1: {uuid1}")
# UUID3: Name-based (MD5 hash)
uuid3 = uuid.uuid3(uuid.NAMESPACE_DNS, 'example.com')
print(f"UUID3: {uuid3}")
# UUID4: Random (most common)
uuid4 = uuid.uuid4()
print(f"UUID4: {uuid4}")
# UUID5: Name-based (SHA-1 hash)
uuid5 = uuid.uuid5(uuid.NAMESPACE_DNS, 'example.com')
print(f"UUID5: {uuid5}")
Useful Methods
import uuid
my_uuid = uuid.uuid4()
# Convert to different formats
print(my_uuid.hex) # Without hyphens
print(my_uuid.bytes) # As 16-byte string
print(my_uuid.int) # As 128-bit integer
print(my_uuid.urn) # As URN
print(my_uuid.version) # Version number (4)