Skip to content
All posts

Generating UUIDs across languages: stdlib vs libraries in 2026

v4 and v7 in JavaScript, Python, Go, Rust and PHP — which ships in the standard library, which needs a package, and the one-liner that works today.

DDDev DeskDeveloper Tools EditorPublished April 27, 20261 min readbeginner

# The short version

Every major language has v4 UUID support — either in stdlib or via a package everyone uses. v7 support is still library-only in 2026, but the libraries are solid.

<div class="callout callout-note" role="note"><div class="callout-title">Note</div><div class="callout-body"><p>Unsure whether you want v4 or v7? <a href="/blog/uuid-v4-vs-v7">UUID v4 vs v7</a> covers the trade-offs. Short answer: v7 for database primary keys, v4 for everything else.</p></div></div>

# JavaScript / TypeScript

Modern browsers and Node 14+ have crypto.randomUUID() — v4 only:


crypto.randomUUID();
// 'f47ac10b-58cc-4372-a567-0e02b2c3d479'

For v7, use the uuid package (v9+):


import { v4, v7 } from "uuid";
v4();  // classic random
v7();  // time-sortable

# Python

Python 3 has uuid in stdlib:


import uuid
str(uuid.uuid4())
# 'f47ac10b-58cc-4372-a567-0e02b2c3d479'

v7 is coming to stdlib in 3.14 (currently a draft PEP). For now, use the uuid-utils package:


from uuid_utils import uuid7
str(uuid7())
# '018f3c9a-1234-7abc-8def-0123456789ab'

# Go

The google/uuid package is the de facto standard. Stdlib doesn't ship a UUID type.


import "github.com/google/uuid"
uuid.New().String()
// v4, random — the most common
uuid.NewV7()
// v7, time-sortable (added in 2024)

# Rust

The uuid crate covers both:


use uuid::Uuid;
Uuid::new_v4().to_string();
// v4, random
Uuid::now_v7().to_string();
// v7, uses current time

Feature flag for v7: uuid = { version = "1", features = ["v4", "v7"] }.

# PHP

Not in stdlib. The community standard is ramsey/uuid:


use Ramsey\Uuid\Uuid;
Uuid::uuid4()->toString();
// v4
Uuid::uuid7()->toString();
// v7 (requires ramsey/uuid 4.7+)

# Database-side generation

Postgres 17 added native v7 support:


-- v4 (available since Postgres 13+)
SELECT gen_random_uuid();
-- v7 (Postgres 17+)
SELECT uuidv7();

MySQL doesn't ship native UUID generation — use the application layer.

SQLite has no native UUID type, so pass a string or randomblob(16):


INSERT INTO t (id) VALUES (lower(hex(randomblob(16))));

# Quick comparison

| Language | v4 location | v7 location (2026) |

|------------|-------------------|--------------------------|

| JavaScript | crypto.randomUUID() stdlib | uuid package |

| Python | uuid stdlib | uuid-utils (→ 3.14 stdlib) |

| Go | google/uuid | google/uuid (same package) |

| Rust | uuid crate | uuid with v7 feature |

| PHP | ramsey/uuid | ramsey/uuid (4.7+) |

| Postgres | gen_random_uuid()| uuidv7() (Postgres 17+) |

# Common bugs

1. Using Math.random() in JS to build UUIDs. It's not cryptographically random. Use crypto.randomUUID() or crypto.getRandomValues().

2. Casting between UUID versions without revalidating. A v4 generator produces version=4 in bit 50; changing that bit breaks the variant field.

3. Serialising UUIDs as strings everywhere. Databases store them more efficiently as 16-byte binary — a UUID column in Postgres, BINARY(16) in MySQL. Strings are 36 bytes; binary is 16.

4. Expecting v7 UUIDs to be strictly monotonic within the same millisecond. The standard guarantees per-ID uniqueness, not per-ms ordering. If you need strict order, use a sequence.

# Generate now

Our UUID Generator produces v4 by default, v7 on a toggle. Bulk up to 1000 at once, copy individually or all together. Everything client-side.

Common questions

Frequently asked.

Is v7 in any language's standard library yet?

Not yet in the major ones — as of 2026, every language needs a third-party library for v7. The IETF only ratified the RFC in 2024. Expect stdlib support to land in Python 3.14, Node 22+ (experimental), and Go's `google/uuid` already has it.

Can I generate UUIDs without a library?

You can if you have a cryptographically secure random source. Every language has one. 16 random bytes + a few bit-twiddles for version and variant = a valid v4. That said, use the library — it's ~20 lines of correct code you don't want to write.

Nieuwe berichten, één keer per week.

Praktische handleidingen voor ontwikkelaars. Geen spam. Uitschrijven kan op elk moment.

Tools mentioned

Pick up where the post leaves off.

Keep reading

More from the field notes.