Skip to main content

o192 — Python

PyPI Python versions License: MIT Spec: v0

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.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.

License

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

Metadata

Release files for o192 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for o192 0.2.2
File Size Uploaded Provenance Actions
o192-0.2.2.tar.gz 15.7 kB Without provenance Details for o192-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for o192 0.2.2
File Interpreter ABI Platform Actions
o192-0.2.2-py3-none-any.whl Python 3 none any Details for o192-0.2.2-py3-none-any.whl

Total release size: 30.8 kB

Release files / o192-0.2.2.tar.gz

Download URL o192-0.2.2.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
110fe38dc724baf7c245634f09bdf36259395b6f1d1f921f961e1362728be48a
BLAKE2b-256 checksum
How to use checksums
93745fbfba60d5529cedb3077c98f9a681459c45ec7628c6906d2fcb946af17c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / o192-0.2.2-py3-none-any.whl

Download URL o192-0.2.2-py3-none-any.whl
Size 15.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a3faef3dfd41f301c79cd1735bd3c4309d9ca119fbdefd582c1358bbdc5f0409
BLAKE2b-256 checksum
How to use checksums
f181f8bfa23337e4102d4ff54d37303a3520e9231df9c1d5df9ba8e26ff8bd15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for o192 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page