UUIDs in your code
How to create, store and read UUIDs in your language or database, with v4, v7 and the libraries that help.
In JavaScript, crypto.randomUUID() needs no library. For v7 and v5 use the uuid package or a few lines of code. Plus validation and a TypeScript type.
- crypto.randomUUID()
- uuid package
- v7 without a library
- TypeScript
The uuid module creates v4 and v5 in Python, and v7 from Python 3.14. Plus parsing, the uuid6 package for older versions and keys in Django and SQLAlchemy.
- uuid4()
- uuid7()
- uuid5()
- Django
- SQLAlchemy
PostgreSQL has a native uuid type, gen_random_uuid() and, from version 18, uuidv7(). Plus a v7 function for older versions and v5 with uuid-ossp.
- uuid type
- gen_random_uuid()
- uuidv7()
- v7 before 18
- uuid-ossp
MySQL has no UUID type: store UUIDs in BINARY(16) with UUID_TO_BIN() and BIN_TO_UUID(). Why UUID() gives v1, when the swap flag helps, and what MariaDB adds.
- BINARY(16)
- UUID_TO_BIN()
- IS_UUID()
- MariaDB
In the shell, uuidgen creates UUIDs on Linux and macOS. Plus v5 from a name, the kernel file on Linux, v7 with curl and checking UUIDs with grep.
- uuidgen
- /proc
- curl
- grep
java.util.UUID creates v4 in Java, while v7 and v5 come from java-uuid-generator. Plus parsing, bytes and JPA keys.
- UUID.randomUUID()
- v7 with a library
- v5
- JPA
In C#, Guid.NewGuid() for v4 and, from .NET 9, Guid.CreateVersion7(). Plus formats, the byte order trap and keys in Entity Framework Core.
- Guid.NewGuid()
- Guid.CreateVersion7()
- formats
- byte order
- EF Core
C++ has no UUID type in the standard library. Boost.Uuid creates random v4, v5 from a name and, in newer Boost versions, v7. Plus parsing and the 16 bytes.
- Boost.Uuid
- random_generator
- name_generator_sha1
- v7
PHP has no UUID function of its own. ramsey/uuid and symfony/uid create v4, v7 and v5, and with random_bytes() a few lines are enough. Plus checking and Laravel.
- ramsey/uuid
- symfony/uid
- random_bytes()
- Laravel
In PowerShell, New-Guid creates a random UUID, and PowerShell 7.5 adds v7 through .NET 9. Plus upper case and braces, checking with TryParse and any version from the API.
- New-Guid
- [guid]::CreateVersion7()
- formats
- Invoke-RestMethod
In Go, the package github.com/google/uuid creates v4, v7 and v5 and reads UUIDs. Plus why New() can panic, and UUIDs in database/sql and JSON.
- github.com/google/uuid
- uuid.NewV7()
- uuid.NewSHA1()
- database/sql
In Rust, the uuid crate creates v4, v7 and v5, but only with the right features. Plus parsing, the formats and UUIDs with serde and sqlx.
- uuid crate
- Uuid::now_v7()
- features
- serde
- sqlx
Kotlin on the JVM uses java.util.UUID, and Kotlin 2.0.20 added kotlin.uuid.Uuid for all platforms. Plus v7 with a library, parsing and a note on Android.
- UUID.randomUUID()
- kotlin.uuid.Uuid
- v7 on the JVM
- Android
In Ruby, SecureRandom.uuid creates v4, and Ruby 3.3 adds uuid_v7. Plus v5 with Active Support, checking with a pattern and UUID primary keys in Rails.
- SecureRandom.uuid
- uuid_v7
- Digest::UUID
- Rails
Swift creates random UUIDs with UUID() from Foundation. Why uuidString is upper case, how to read UUIDs, a short v7 function and UUIDs in Codable and SwiftData.
- UUID()
- uuidString
- v7 by hand
- Codable