Skip to main content

The v9 UUID supports both time-based sequential and random non-sequential IDs with an optional prefix, an optional checksum, and sufficient randomness to avoid collisions.

Project description

UUID v9

The v9 UUID supports both time-based sequential and random non-sequential UUIDs with an optional prefix, an optional checksum, and sufficient randomness to avoid collisions. It uses the UNIX timestamp for sequential UUIDs and CRC-8 for checksums. A version digit can be added if desired, but is omitted by default.

Installation

Install UUID v9 from PyPI.

python3 -m pip install uuid-v9

Usage

from uuid_v9 import uuidv9, is_valid_uuidv9

ordered_id = uuidv9()
prefixed_ordered_id = uuidv9('a1b2c3d4') # up to 8 hexadecimal characters
unordered_id = uuidv9('', False)
prefixed_unordered_id = uuidv9('a1b2c3d4', False)
ordered_id_with_checksum = uuidv9('', True, True)
ordered_id_with_version = uuidv9('', True, True, True)
ordered_id_with_compatibility = uuidv9('', True, False, False, True)

const is_valid = validate_uuidv9(ordered_id) # build-in UUID validator
const is_valid_with_checksum = validate_uuidv9(ordered_id_with_checksum, True)
const is_valid_with_version = validate_uuidv9(ordered_id_with_version, True, True)
const is_valid_with_compatibility = validate_uuidv9(ordered_id_with_compatibility, True, '1')

Command Line Usage

python3 uuid_v9.py
python3 uuid_v9.py --prefix 'a1b2c3d4' # add a prefix
python3 uuid_v9.py --unordered # omit the timestamp
python3 uuid_v9.py --checksum # add a CRC-8 checksum
python3 uuid_v9.py --version # add a version 9 digit
python3 uuid_v9.py --backcompat # compatibility mode (see below)

Compatibility

Some UUID validators check for specific features of v1 or v4 UUIDs. This causes some valid v9 UUIDs to appear invalid. Three possible workarounds are:

  1. Use the built-in validator (recommended)
  2. Use compatibility mode*
  3. Bypass the validator (not recommended)

*Compatibility mode adds version and variant digits to immitate v1 or v4 UUIDs based on whether or not you have a timestamp.

Format

Here is the UUID v9 format: xxxxxxxx-xxxx-9xxx-8xxx-xxxxxxxxxxyy

x = prefix/timestamp/random, y = checksum (optional), 9 = version (optional), 8 = variant (compatibility mode)

License

This project is licensed under the MIT License.

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

uuid-v9-0.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

uuid_v9-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file uuid-v9-0.1.0.tar.gz.

File metadata

  • Download URL: uuid-v9-0.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for uuid-v9-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dad2384f491c6ead0de045a65a189c1f98b897de3b96a06a30b742cb423a22e5
MD5 7f8c7ce0376ef2a6d1156c30e5cc7d4f
BLAKE2b-256 42c7c13577a8abe9cac4ba2a55bc5e3cd2014eb8b6284b89ede96c14af81df08

See more details on using hashes here.

File details

Details for the file uuid_v9-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: uuid_v9-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for uuid_v9-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b883a76f0c6cce5abf64d19d6f101e8b42aca12ff5b8e0b85e7df020fb0ee3fe
MD5 811ce208b761b91bfa1e7e795f29ce4c
BLAKE2b-256 fbba05be5640adffb4c8f87068dfd3c5ed8b0134004c2da0f25581f97a72a14a

See more details on using hashes here.

Supported by

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