UUID Generator — Developer Code Samples

UUIDs (Universally Unique Identifiers) are 128-bit identifiers with an astronomically low collision probability. UUID v4 is random, v1 is time-based, and v5 is name-based with SHA-1 hashing. Python's uuid module and Node's crypto module generate them natively.

Try the interactive version online: Open UUID Generator Tool →

Parameters

Parameter Type Required Description
version int No UUID version: 1 (time-based), 4 (random), 5 (name-based) (default: 4)
namespace str No For v5: namespace UUID (e.g., uuid.NAMESPACE_DNS)
name str No For v5: name string to hash into UUID

Returns: UUID string in standard format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Code Examples

import uuid

# Generate a random UUID v4 (most common)
uid = uuid.uuid4()
print(uid)
# Output: 550e8400-e29b-41d4-a716-446655440000 (random each time)

# UUID as string
uid_str = str(uuid.uuid4())
print(uid_str)

# UUID without hyphens (used in some databases)
uid_clean = uuid.uuid4().hex
print(uid_clean)
# Output: 550e8400e29b41d4a716446655440000

# UUID v1 (time-based, includes MAC address)
uid_v1 = uuid.uuid1()
print(f"v1: {uid_v1}")

# UUID v5 (name-based, deterministic)
namespace = uuid.NAMESPACE_DNS
uid_v5 = uuid.uuid5(namespace, "example.com")
print(f"v5: {uid_v5}")  # Always the same for same input

# Generate multiple UUIDs
uuids = [str(uuid.uuid4()) for _ in range(5)]
for u in uuids:
    print(u)

# Validate a UUID string
def is_valid_uuid(val):
    try:
        uuid.UUID(str(val))
        return True
    except ValueError:
        return False

print(is_valid_uuid("550e8400-e29b-41d4-a716-446655440000"))  # True
print(is_valid_uuid("not-a-uuid"))  # False