Fast, lightweight, zero-dependency Python implementation of UUID version 9
Project description
UUID v9
Fast, lightweight, zero-dependency Python implementation of the UUID version 9 proposal.
The v9 UUID supports both sequential (time-based) and non-sequential (random) UUIDs with an optional prefix of up to four bytes, 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.
To learn more about UUID v9, please visit the website: https://uuidv9.jhunt.dev
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(prefix='a1b2c3d4')
unordered_id = uuidv9(timestamp=False)
prefixed_unordered_id = uuidv9(prefix='a1b2c3d4', timestamp=False)
ordered_id_with_checksum = uuidv9(checksum=True)
ordered_id_with_version = uuidv9(checksum=True, version=True)
ordered_id_with_compatibility = uuidv9(legacy=True)
const is_valid = validate_uuidv9(ordered_id)
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 --random # 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 --legacy # legacy mode (see Backward Compatibility below)
Backward 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:
- Use the built-in validator (recommended)
- Use compatibility mode*
- Bypass the validator (not recommended)
*Legacy mode adds version and variant digits to immitate v1 or v4 UUIDs depending on the presence of a timestamp.
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
Built Distribution
File details
Details for the file uuid_v9-0.2.0.tar.gz
.
File metadata
- Download URL: uuid_v9-0.2.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2274830926d08847a0de951d8ff6987b18261692a92276722ff55ad5a2f376f0 |
|
MD5 | 278164f29b2d79710e61b6e5e76b8172 |
|
BLAKE2b-256 | a0e8b0f4661308b41fb448eaf8bcfdc8f8252e1ef9dd5d8a35a0a0d7303edab9 |
File details
Details for the file uuid_v9-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: uuid_v9-0.2.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61d47e2f24c460a95da1f519a3f6b23387c68a70d8a6ac96209c1a833b3c58da |
|
MD5 | bdf14f5fdde85601d262271aa54d441a |
|
BLAKE2b-256 | 74b650dc568c0702f747582093eff9d53d683550e339f7f93da0559e2dd91c22 |