Skip to main content

ORION-192: ordered, resilient, independent, URL-safe 192-bit IDs for distributed systems.

Project description

o192 — Python

PyPI Python versions License: MIT Spec: v0

Python reference implementation of ORION-192Ordered, 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.typed marker, and is mypy --strict clean.
  • 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

License

Licensed under the MIT License — Copyright © 2026 Lam Hieu and contributors.

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

o192-0.2.0.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

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

o192-0.2.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file o192-0.2.0.tar.gz.

File metadata

  • Download URL: o192-0.2.0.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

Hashes for o192-0.2.0.tar.gz
Algorithm Hash digest
SHA256 dfc2c0dda28a6b4c5ecf9d26968618304809b5310f90e990b1a259ff8df62ff4
MD5 557ac8f580c9244bea2e22f500c00aea
BLAKE2b-256 8d81fab382efb339b74ad91c258e1746574458a715feb5d04a898e53c0798a40

See more details on using hashes here.

File details

Details for the file o192-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: o192-0.2.0-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

Hashes for o192-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa55b0fc8fbecd70f242a6200c788b95099706dedcac3a72a8b89fdfc5c3c0a4
MD5 bc4e2d0998a9ef9db5930bf186899032
BLAKE2b-256 5b7677363a402d5551b0be58f1cf8783e8274bae6b14e4e9e4a10ed3b0321d3b

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