UUID in Python

Python UUID Generator

Python's uuid module covers the whole of RFC 9562 — and since 3.14 it includes the versions developers were previously pip-installing.

Standard libraryv4, v5, v6, v7, v8NIL and MAX

Generated locally with the Web Crypto API — nothing leaves your browser.

Generating UUIDs in Python

How to generate

  1. Press Generate UUID above to mint a value in this browser — nothing is sent anywhere.
  2. Copy one value with Copy, or set How many and use Copy all for a fixture list.
  3. Switch Version if your code needs v7 instead of the v4 default, and turn on Formatting to match your stack's conventions.

Use Cases

How Python UUID Generator Compares

uuid.uuid4()Random, CSPRNG, the safe default
uuid.uuid7()Time-ordered — Python 3.14+, or the uuid6 package
uuid.uuid5()Deterministic from a name; same input, same ID, always

Code Examples

Python
import uuid

str(uuid.uuid4())          # v4, random  -> '65e82210-1a2d-4011-a064-a6a60565aa41'
uuid.uuid7()               # v7, time-ordered (Python 3.14+)
uuid.uuid5(uuid.NAMESPACE_DNS, 'example.com')  # deterministic
uuid.NIL                   # 00000000-0000-0000-0000-000000000000 (3.14+)

u = uuid.uuid4()
u.hex                      # 32 chars, no hyphens
u.bytes                    # 16 raw bytes
Django
import uuid
from django.db import models

class Order(models.Model):
    # Pass the function, NOT uuid.uuid4() — calling it would give every
    # row the same value.
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

Frequently Asked Questions

How do I get a UUID v7 in Python?
On Python 3.14 or later, uuid.uuid7() is in the standard library. On 3.13 and earlier, install the uuid6 package and call uuid6.uuid7().
Why do all my rows get the same UUID in Django?
You wrote default=uuid.uuid4() with parentheses. That evaluates once at import time; pass the function itself — default=uuid.uuid4.
Is the Python uuid module cryptographically secure?
uuid4() is — it is seeded from os.urandom. uuid1() embeds the host MAC address and timestamp instead, so avoid it for anything user-visible.

Related tools