Skip to main content

Generate UUID version 8 identifiers as defined in RFC 9562 — custom-use UUIDs with cryptographically random fields

Project description

uuidv8

Generate UUID version 8 identifiers as defined in RFC 9562.

f6440f3e-14a2-8293-add2-1066de13086a
         ^^^^                          ← version = 8
                   ^                  ← variant = 10xx

No dependencies. Uses only the Python standard library (secrets).


What is UUID v8?

UUID v8 is a custom-use UUID format introduced in RFC 9562 alongside the more widely known v7. Where v7 is opinionated (millisecond timestamp + random bits), v8 leaves 122 of its 128 bits entirely up to you.

The spec only mandates two things:

Bits Field Value
48–51 version 1000 (= 8)
64–65 variant 10

Everything else — the remaining 122 bits split across custom_a, custom_b, and custom_c — is yours to define.

This package fills all custom fields with cryptographically random bytes, making it a drop-in for any situation where you need a universally unique, opaque identifier and none of the earlier UUID versions quite fit.


When to use UUID v8

Situation Good fit?
You need a random, unique ID with no embedded meaning Yes — same collision resistance as v4
You want a UUID that signals "custom / vendor-specific" to readers of your schema Yes — the 8 version nibble is a clear marker
You are building a proprietary UUID layout (e.g. embedding a shard ID or timestamp in your own format) Yes — swap in your own bits instead of random ones
You need time-sortable IDs No — use UUID v7
You need backwards compatibility with systems that only accept v4 No — use UUID v4

Installation

pip install uuidv8

Requires Python 3.8 or later. No third-party dependencies.


Usage

from uuidv8 import uuidv8, validate

uid = uuidv8()
print(uid)            # "f6440f3e-14a2-8293-add2-1066de13086a"
print(validate(uid))  # True

API

uuidv8() -> str

Returns a new UUID v8 string with cryptographically random custom fields.

uuidv8()  # "a1b2c3d4-e5f6-8abc-9def-0123456789ab"

The returned string is always lowercase and follows the standard 8-4-4-4-12 hyphenated format.

validate(uuid: object) -> bool

Returns True if the given value is a valid UUID v8 (correct format, version nibble = 8, variant bits = 10xx). Returns False for anything else, including other UUID versions.

validate("a1b2c3d4-e5f6-8abc-9def-0123456789ab")  # True  — valid v8
validate("f47ac10b-58cc-4372-a567-0e02b2c3d479")  # False — this is v4
validate("not-a-uuid")                             # False
validate(None)                                     # False

UUID v8 layout

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                          custom_a                             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           custom_a            |  ver  |       custom_b        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|var|                       custom_c                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                           custom_c                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Field Bits Value (this package)
custom_a 48 random
ver 4 8
custom_b 12 random
var 2 10
custom_c 62 random

License

GPL-3.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uuidv8-1.0.0.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uuidv8-1.0.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file uuidv8-1.0.0.tar.gz.

File metadata

  • Download URL: uuidv8-1.0.0.tar.gz
  • Upload date:
  • Size: 27.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for uuidv8-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9eb3bfaab383647edce76e4a6e2617d81ef49d76b9e5e8219c10dd27fcefbce4
MD5 e3272c12f00072955e165a437cdb275c
BLAKE2b-256 3bd46fea5a92d50fb98ec2f96b1b7d4a5fcdddd4edef0088b44525a70c1b96e6

See more details on using hashes here.

File details

Details for the file uuidv8-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: uuidv8-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for uuidv8-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 67ddcd7dfbc8010d7719ca0714cafd469f9e93d528e978e417a8a1bdcde0a8cd
MD5 178952a02a127ea6365f66c11429d1ee
BLAKE2b-256 72a06d57bbf8c48de461062d6eed406fe8ab7aaa75654a042355ef8be9c672ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page