Skip to main content

Fast, lightweight, and dependency-free implementation of the UUID version 9 proposal for Python.

Project description

UUID v9

Fast, lightweight, and dependency-free implementation of the UUID version 9 proposal for Python.

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.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

uuid_v9-0.1.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: uuid-v9-0.1.1.tar.gz
  • Upload date:
  • Size: 4.8 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.1.tar.gz
Algorithm Hash digest
SHA256 837de947159c64d47b4e78b8c34f715b16a166af35c563b161f3d3faa5ebe90c
MD5 ceffa1ce1ffe971b7f8db12d196cc686
BLAKE2b-256 e9fcc27409b1272fa52fc15fc2654aead86f3bd68d9a4891c8f03cf129a2cb54

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uuid_v9-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.5 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a279b3122930b75109f37fac96716d26457f63936a3e8971a5a55d93a6438985
MD5 74d88bcce6161f607f02cb2fd55659bf
BLAKE2b-256 ebb632c3f5990446948fc850969cfcc2b7ff36ff52020fad8b600e7afdd0330e

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