HLID: a Human Lexicographically (sortable) Identifier
Project description
HLID: a Human Lexicographically (sortable) Identifier
The HLID is a human-readable lexicographically sortable identifier that borrows similar concepts from -
- ULID (Universally-Unique, Lexicographically-Sortable Identifier) - github.com/ulid
- UUID7 (Time-ordered UUID with millisecond precision) - ietf.org
HLIDs have the following properties -
- Time sortable
- Human readable in UTC timezone
- 10^4 seconds time resolution (tenth of milliseconds)
- 8 bits of user-data (two hex chars)
- 48 bits of nonce; optionally derived from a truncated hmac-sha256 (12x hex chars)
- Can be swapped with UUID-type or ULID-type values
With all good things there are tradeoffs -
- These values are not cryptographically secure for inputs into to strong crypto routines.
- HLID can provide at best tenth-of-millisecond time resolution, whereas UUID7 provides 50 nanosecond resolution.
- Because the HMAC is truncated, a larger secret value is enforced (128 bits).
For example a HLID value -
20241105-1108-5200-00ff-8fa646f09a7e
^ ^ ^ ^ ^ ^ ^
| | | | | | |- 12x hex: nonce-value -or- hmac-value
| | | | | |- 2x hex: one byte of user-data; 2x hex chars
| | | |+ |- 4x digits: -10^4 seconds; tenth of millisecond
| | |- 2x digits: seconds
| |- 4x digits: hours and minutes
|- 8x digits: year and month and day
All values are zero-padded when required.
Install
pipx install hlid
Usage
Example: HLID attributes
>>> from hlid import HLID
>>> hlid = HLID()
>>> print(str(hlid))
20250213-1615-0320-9000-723da4092594
>>> print(f"{hlid.hex=}")
hlid.hex='20250213161503209000723da4092594'
>>> print(f"{hlid.age=}")
hlid.age=0.000799
>>> print(f"{hlid.time=}")
hlid.time=1739463303.209
>>> print(f"{hlid.datetime=}")
hlid.datetime=datetime.datetime(2025, 2, 13, 16, 15, 3, 209000, tzinfo=datetime.timezone.utc)
Example: Handle existing HLID values
>>> from hlid import HLID
>>> hlid1 = HLID()
>>> hlid2 = HLID(hlid1.hex)
>>> assert hlid1.hex == hlid2.hex
Example: HMAC signed HLIDs
>>> from hlid import hlid, HLID
>>> from uuid import uuid4
>>> secret = uuid4().hex
>>> hlid_signed = hlid(secret=secret)
>>> print(hlid_signed)
20250213-1613-0211-8000-c199fc3695c5
>>> hlid_test = HLID(hlid_signed.hex, secret=secret)
>>> print(hlid_test)
20250213-1613-0211-8000-c199fc3695c5
>>> bad_secret = uuid4().hex
>>> HLID(hlid_signed.hex, secret=bad_secret)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ndejong/.local/venvs/hlid/lib/python3.12/site-packages/hlid/__init__.py", line 65, in __init__
raise ValueError("HLID fails HMAC check.")
ValueError: HLID fails HMAC check.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
hlid-0.1.4.tar.gz
(4.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
hlid-0.1.4-py3-none-any.whl
(5.2 kB
view details)
File details
Details for the file hlid-0.1.4.tar.gz.
File metadata
- Download URL: hlid-0.1.4.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29fb5a55c9fbdd182796dfb92c3eaa55ec3cf35aac032ec8b661200f142b206f
|
|
| MD5 |
81da7949fd4bee8a5d7b51e580f7e375
|
|
| BLAKE2b-256 |
06276e146c9be2778949aa3d3e66148019fe417da849d0818028ed410e81514a
|
File details
Details for the file hlid-0.1.4-py3-none-any.whl.
File metadata
- Download URL: hlid-0.1.4-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f586d66f702881d9f78d9a340e41696ee3d0b2b29a0e179f0bc19551484c4d02
|
|
| MD5 |
3cf8cd2289c059f7c03d21d2e7d1c76d
|
|
| BLAKE2b-256 |
949052a962ff5174fe694c597e3aa85ca4c5f095654844a561e82cb3ac2523c2
|