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

Uploaded Python 3

File details

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

File metadata

  • Download URL: odoid-1.0.1.tar.gz
  • Upload date:
  • Size: 8.2 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.1.tar.gz
Algorithm Hash digest
SHA256 f400a7aa6e7fce30c280a5640dd62d79a6f21cab1f445761c8679aff3d3b782f
MD5 e04185d053f3d1efd85716efd16eb8d3
BLAKE2b-256 d02c517c4f181dfeb16abd0a4ab55949ef7133d7711a29fdecbadbf91315e837

See more details on using hashes here.

File details

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

File metadata

  • Download URL: odoid-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f43f0c098bb62ae6a84881d5ad24c5cfd7df10a5396e011011bb7cf9400e2554
MD5 3a343380f1297b7e5a053dc32c10c127
BLAKE2b-256 2d419f5535e426a2023cdb5fd17b148504c22801cb5b315ed17f6b51d80a4499

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