ORION-192: ordered, resilient, independent, URL-safe 192-bit IDs for distributed systems.
Project description
o192 — Python
Python reference implementation of ORION-192 — Ordered, Resilient, Independent, Opaque-ish, Non-coordinated 192-bit identifiers for distributed systems.
ORION-192 produces fixed-width, URL-safe, lexicographically sortable IDs without a central coordinator, worker ID, or machine identity in the wire format. This package is byte-compatible with the JavaScript and Rust reference implementations.
Highlights
- Zero runtime dependencies. The CSPRNG comes from the standard library (
os.urandom/secrets). - Fully typed, ships a
py.typedmarker, and ismypy --strictclean. - Supports CPython 3.9+ and PyPy; pure-Python source, no native build step.
- Strictly monotonic within a generator instance, including across clock rollback.
- Wire-compatible with the JavaScript and Rust packages — same 24-byte layout, same 32-character canonical form.
Install
python -m pip install o192
Quick start
from o192 import orionid, OrionIdGenerator, parse, is_valid
# 1. One-shot helper
print(orionid()) # → "0Pu_iDKVO9012BwIEM28oFojPMWLWeLU"
# 2. Long-lived generator (recommended for sustained throughput)
gen = OrionIdGenerator(epoch_ms=1_735_689_600_000) # 2025-01-01 UTC
a, b = gen.next(), gen.next()
assert a < b # strictly monotonic per generator
# 3. Parse and inspect
if is_valid(a):
view = parse(a, epoch_ms=1_735_689_600_000)
print(view.unix_datetime, view.fraction4096, view.counter)
Command-line
The package installs an o192 console entry point:
o192 # prints a single ORION-192 id
python -m o192 # equivalent
API
Top-level helpers
def orionid() -> str: ...
def parse(identifier: str, *, epoch_ms: int = 0) -> ParsedOrionId: ...
def is_valid(identifier: str) -> bool: ...
def encode_sortable64(data: bytes | bytearray | memoryview) -> str: ...
def decode_sortable64(identifier: str) -> bytes: ...
OrionIdGenerator
OrionIdGenerator(
*,
epoch_ms: int = 0, # private epoch in ms
random_pool_bytes: int = 65_536, # 14 .. 16 MiB
clock: Callable[[], int] | None = None, # test-only
random_bytes: Callable[[int], bytes] | None = None, # test-only
)
generator.next() -> str # 32-char canonical string
generator.next_bytes() -> bytes # 24-byte binary form
generator.parse(identifier: str) -> ParsedOrionId
# Read-only telemetry
generator.epoch_ms: int
generator.last_time_key: int # -1 before the first call
generator.counter: int # 20-bit counter
generator.clock_rollbacks: int # observed backward jumps
generator.synthetic_ticks: int # counter-overflow advances
ParsedOrionId
@dataclass(frozen=True, slots=True)
class ParsedOrionId:
id: str # original canonical string
binary: bytes # 24-byte binary form
unix_ms: int # relative_ms + epoch_ms
unix_datetime: datetime | None
relative_ms: int # 48-bit ms field
fraction4096: int # 12-bit sub-ms fraction
approx_sub_ms: float # fraction4096 / 4096, in ms
counter: int # 20-bit counter
random_hex: str # 14-byte tail as lower-case hex
Errors
class OrionIdError(ValueError):
code: str
# One of: INVALID_LENGTH, INVALID_CHARACTER, INVALID_OPTION,
# TIMESTAMP_OVERFLOW, COUNTER_OVERFLOW, RANDOM_FAILURE
OrionIdError subclasses ValueError, so existing except ValueError handlers continue to work. Inspect error.code for programmatic handling.
Performance
A single OrionIdGenerator produces roughly 400 k – 1 M IDs/second on a modern laptop under CPython, and noticeably more under PyPy. Numbers are indicative — run the bundled benchmark on your target hardware:
python ../../benchmarks/python_bench.py
Status
ORION-192 is at spec v0 — implementation-complete, cross-language conformant, and wire-frozen. See the project status for the full stability statement.
Specification & related
- Specification (
SPEC.md) — normative wire format and algorithm. - Design rationale (
docs/RATIONALE.md) — why 192 bits, why this layout. - Storage guide (
docs/DATABASE.md) — column types, collation, indexing. - Security policy (
SECURITY.md) — threat model and disclosure process. - Sibling implementations: JavaScript · Rust.
License
Licensed under the MIT License — Copyright © 2026 Lam Hieu and contributors.
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
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 o192-0.2.1.tar.gz.
File metadata
- Download URL: o192-0.2.1.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1ccdbb9fd139c975e563487201e797c515f95972464e514c15e547166e33963
|
|
| MD5 |
93485e88f711f2169653f019412bcb3e
|
|
| BLAKE2b-256 |
cb97e93e38dba70e4a2fa9c37fc42925047f51d3f428bc2f25c545a83208bfd0
|
File details
Details for the file o192-0.2.1-py3-none-any.whl.
File metadata
- Download URL: o192-0.2.1-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
daa2efbf1facf9823666cbd239bbe7e3ed308cddff7dbfb92b51f40f836e17ec
|
|
| MD5 |
3e4a3b6076846b664fab4d7a979c9eec
|
|
| BLAKE2b-256 |
52221900aea639bf1184077b1172dcdba1d10528bff74840f8ef7cc26e8dc643
|