Skip to main content

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, O are 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

odoid-1.0.2.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

odoid-1.0.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file odoid-1.0.2.tar.gz.

File metadata

  • Download URL: odoid-1.0.2.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for odoid-1.0.2.tar.gz
Algorithm Hash digest
SHA256 42cbfc3d71b1acaccddfd70c2cb1aaf3d189f3421f0aeff95a099461d62940b5
MD5 48a438caf4dd2ea5a09587de03e4b665
BLAKE2b-256 78525ec989fb4753b6f77699bdd886236fdd3f31f0b2874591e974c11c083ca8

See more details on using hashes here.

File details

Details for the file odoid-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: odoid-1.0.2-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

Hashes for odoid-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 76244e79a486bf37133c4aaa9bda2ded0f56aa677a820c230e7713491e15f0f9
MD5 82be5ba624d24f2dcadcf05934c389f6
BLAKE2b-256 be33f1087729cc0bc5cca1b85d4f1f1aa37c970a8daea5b9dda8a3844bee0ca5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page