Deterministic mixed-radix ID encoding — maps integers to 6, 7, or 8-character alphanumeric strings.
Project description
odoid
Deterministic mixed-radix ID encoding. Maps a non-negative integer to a 6, 7, or 8-character alphanumeric string with a serial-number aesthetic.
encode(0, 6) → "0A0000"
encode(1234567, 6) → "0D7NM7"
encode(1234567, 7) → "0A15NM7"
encode(236223201279, 8) → "ZZ9ZZZZZ"
Features
- Deterministic — same integer + length always produces the same string, and vice-versa.
- Human-readable — ambiguous characters
I,L,Oare excluded from all positions. - Fixed positional structure — position 1 is always a letter, position 2 is always a digit.
- Pure Python — no dependencies, works on Python 3.8+.
Install
pip install odoid
Usage
Encode
from odoid import encode
encode(0, 6) # "0A0000"
encode(1234567, 6) # "0D7NM7"
encode(1234567, 7) # "0A15NM7"
encode(236223201279, 8) # "ZZ9ZZZZZ"
encode(n, length=6) — default length is 6.
Decode
from odoid import decode
decode("0A0000") # 0
decode("0D7NM7") # 1234567
decode("0A15NM7") # 1234567
Returns int. Input is uppercased before lookup, so decode("0d7nm7") is valid.
OdoIDGenerator
from odoid import OdoIDGenerator
g = OdoIDGenerator(namespace="orders", length=7)
result = g.next()
# result.id → e.g. "3H5NV2K"
# result.n → the raw integer
# result.length → 7
# result.namespace → "orders"
Lengths and Capacity
| Length | Max integer (exclusive) |
|---|---|
| 6 | 230,686,720 |
| 7 | 7,381,975,040 |
| 8 | 236,223,201,280 |
Errors
| Error | When |
|---|---|
OverflowError |
n < 0 or n >= MAX[length] |
UnsupportedLengthError |
length is not 6, 7, or 8 |
InvalidCharacterError |
character not in positional charset during decode |
All three are subclasses of ValueError.
Specification
See SPEC.md for the full processing instruction document.
License
MIT
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
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
File details
Details for the file odoid-1.0.0.tar.gz.
File metadata
- Download URL: odoid-1.0.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
076a00b45231211a7091b793efe445187582ad55b226cf3762284c3bf8a08ec0
|
|
| MD5 |
4d6dc1f573a10985fbe4122cdfa5e5ce
|
|
| BLAKE2b-256 |
130f3e82b232746224fd4f5dd6211c6fd18396b5e85440935c5f607a0002894c
|
File details
Details for the file odoid-1.0.0-py3-none-any.whl.
File metadata
- Download URL: odoid-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64b718e35cd0e0bf619f210e6bfc02e090a8e37e7f14911f0ccbdb66d6ae4ec1
|
|
| MD5 |
688f45776e086eda77f7b80b7075f815
|
|
| BLAKE2b-256 |
1353cb31fd36752e969695dde1cae9b57a7105d8f1f6388638807403ffd9ed86
|