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.3.tar.gz (5.6 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.3-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: odoid-1.0.3.tar.gz
  • Upload date:
  • Size: 5.6 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.3.tar.gz
Algorithm Hash digest
SHA256 4576bcc5f0c69e44b7df3451872c0d3aedcbdbc7b06a7e6a5573d0d9eec040ea
MD5 035377118d33fb815ef22d9a92a0d1b9
BLAKE2b-256 31c2641d1a211e04b01f9630a0834e362975034306a1c38c994f3c216f706c72

See more details on using hashes here.

File details

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

File metadata

  • Download URL: odoid-1.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1f5360d2f0d2e2871b9dde7e744df71b71776586d70b3761a80b56f9bc285b1e
MD5 765ffb9b1cf63ad21eb1374f40ea553f
BLAKE2b-256 f99c8a966f2fa731ea8392a833ae2e703a2d9a73f721a08399e85d6f099f6fd7

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