How to Generate UUIDs in JavaScript, Python, and Go
Learn how to generate UUID v4 identifiers in the three most popular programming languages, plus a free online generator.
What is a UUID?
A UUID (Universally Unique Identifier) is a 128-bit identifier that's practically guaranteed to be unique. The most common version, UUID v4, uses random numbers.
Format: 550e8400-e29b-41d4-a716-446655440000
JavaScript
Modern browsers and Node.js support crypto.randomUUID():
const uuid = crypto.randomUUID();
console.log(uuid);
// "550e8400-e29b-41d4-a716-446655440000"
No dependencies needed! This is available in all modern browsers and Node.js 16+.
Python
Python has a built-in uuid module:
import uuid
new_uuid = uuid.uuid4()
print(new_uuid)
# 550e8400-e29b-41d4-a716-446655440000
Go
Go's google/uuid package is the standard choice:
package main
import (
"fmt"
"github.com/google/uuid"
)
func main() {
id := uuid.New()
fmt.Println(id.String())
}
Quick Generator
Don't want to write code? Use our UUID Generator to create UUIDs instantly. Supports bulk generation, uppercase, and no-dashes format.
When to Use UUIDs
- Database primary keys — avoid sequential IDs that expose record counts
- API request IDs — trace requests across microservices
- File names — prevent collisions in upload systems
- Session tokens — unique identifiers for user sessions
UUID v4 vs Others
| Version | Source | Use Case | |---------|--------|----------| | v1 | Timestamp + MAC | Time-ordered, but exposes hardware info | | v4 | Random | Most common, no information leakage | | v5 | Namespace + SHA-1 | Deterministic from input | | v7 | Timestamp + Random | New! Time-ordered like v1 but random |
For most use cases, v4 is the best choice — it's simple, random, and widely supported.