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 uuid, is_valid_uuid

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

const is_valid = validate_uuid(ordered_id) # build-in UUID validator
const is_valid_with_checksum = validate_uuid(ordered_id_with_checksum, True)
const is_valid_with_version = validate_uuid(ordered_id_with_version, True, True)
const is_valid_with_compatibility = validate_uuid(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 will not accept some v9 UUIDs. 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.0.4.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: uuid-v9-0.0.4.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.0.4.tar.gz
Algorithm Hash digest
SHA256 d797c3463d3f6e5b089f615b5680067c2355a465b83c4a527c10b6667b239981
MD5 8dea0d1d6bd1733e4657447e87b914bf
BLAKE2b-256 3f0074b75bf16a2d689f8c45c9ab73ed5b9c472e9ddf6cfddf64980815b9e460

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uuid_v9-0.0.4-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.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3fc5f35a77912df4f360ab513061ecb8f6b18d81aedb19f71cc68062bec77163
MD5 344dec98a51b8240dce5c615c208b3e7
BLAKE2b-256 4c5094d2ea33acf3219bf0a607886942514ccf1d236d245b86c2c40d89ab5a8d

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