AG UUID

Python UUID

How to generate a standard UUID (typically v4) in Python, using the standard library or a widely used package.

Code

main.py
import uuid

uuid.uuid4()      # random v4
uuid.uuid1()      # time-based v1
# UUID('3f2a9c8b-4d1e-4a7b-9c2d-1e2f3a4b5c6d')
Most languages provide v4 (random) out of the box, while v7 or ULID may require a separate library.

View version reference →