ORIONIS API REFERENCE

THE ORIONIS API

Build with clarity.

Explore the building blocks of an async-first Python framework. Every module, class, and method — connected, searchable, and ready to build with.

class documentation

class HTTPRequestPrinter(IHTTPRequestPrinter): (source)

Constructor: HTTPRequestPrinter()

View In Hierarchy

Queue and display formatted HTTP request timing information.

Method __init__ Initialize the HTTPRequestPrinter instance.
Async Method __worker Write queued lines to stdout in the background.
Method printRequest Print a formatted HTTP request line to stdout or queue.
Method setEnabled Set whether to enable or disable console output for HTTP requests.
Async Method start Start the background print worker.
Method startTimer Capture the current high-resolution timestamp for request timing.
Async Method stop Drain remaining output and stop the background worker.
Constant HTTP_COLORS (bg_ansi, fg_ansi) tuples for HTTP methods.
Constant HTTP_MIN_STATUS_CODE Minimum valid HTTP status code.
Constant STATUS_COLORS (bg_ansi, fg_ansi) tuples for HTTP status categories.
Instance Variable __enabled Enable HTTP request printing to console by default.
Instance Variable __lifecycle_lock Serialize worker startup and shutdown.
Instance Variable __queue Async queue and worker task (initialized by start()).
Instance Variable __start_timer Context-local timestamp set by startTimer for each request.
Instance Variable __status_icons Precompute status icons by HTTP code category.
Instance Variable __worker_task Background task responsible for draining queued output.
Instance Variable _flush Flush obtained from sys.stdout.flush.
Instance Variable _total_width Total width produced by max.
Instance Variable _write LOAD_FAST vs sys.stdout LOAD_GLOBAL+LOAD_ATTR.
def __init__(self: Self): (source)

Initialize the HTTPRequestPrinter instance.

Determines terminal width, precomputes reusable ANSI-coloured strings, and prepares the async queue and worker task references.

Returns
NoneThis method does not return a value.
async def __worker(self: Self, queue: asyncio.Queue[str]): (source)

Write queued lines to stdout in the background.

Continuously reads lines from the internal async queue and writes them to stdout, flushing after each write to ensure immediate display.

Parameters
queue:asyncio.Queue[str]Queue owned by this worker until shutdown.
Returns
NoneThis method does not return a value.
def printRequest(self: Self, adapter: TransportAdapter, response: Response): (source)

Print a formatted HTTP request line to stdout or queue.

Computes the elapsed duration from start_time, builds an ANSI-coloured output line, and either enqueues it for the background worker (if start() was called) or writes directly to stdout.

Parameters
adapter:orionis.http.adapters.request.contracts.transport.TransportAdapterThe transport adapter providing method and path information.
response:orionis.http.ResponseThe HTTP response object.
Returns
NoneThis method does not return a value.
def setEnabled(self: Self, *, enabled: bool): (source)

Set whether to enable or disable console output for HTTP requests.

Parameters
enabled:boolIf True, HTTP requests are printed to console. If False, output is suppressed.
Returns
NoneThis method does not return a value.
async def start(self: Self): (source)

Start the background print worker.

Create the internal async queue and a worker, or reuse the active worker. Serialize startup with shutdown and close a rejected worker coroutine.

Returns
NoneThis method does not return a value.
def startTimer(self: Self) -> float | None: (source)

Capture the current high-resolution timestamp for request timing.

Returns None immediately if printing is disabled, avoiding unnecessary work when output has been suppressed via setEnabled(enabled=False).

Returns
float | NoneA high-resolution monotonic timestamp from time.perf_counter(), or None if output is disabled.
async def stop(self: Self): (source)

Drain remaining output and stop the background worker.

Close queue admission and await the worker directly, so a failed writer cannot strand shutdown behind unfinished queue items. Release references after success, failure, or cancellation. Safe before startup.

Returns
NoneThis method does not return a value.
Raises
OSErrorIf the output stream fails while writing or flushing.
asyncio.CancelledErrorIf shutdown or the worker is cancelled.

(bg_ansi, fg_ansi) tuples for HTTP methods.

Value
{'GET': (_BG_GREEN, _FG_BLACK),
 'POST': (_BG_BLUE, _FG_WHITE),
 'PUT': (_BG_YELLOW, _FG_BLACK),
 'PATCH': (_BG_MAGENTA, _FG_WHITE),
 'DELETE': (_BG_RED, _FG_WHITE),
 'OPTIONS': (_BG_CYAN, _FG_BLACK),
 'HEAD': (_BG_WHITE, _FG_BLACK),
...
HTTP_MIN_STATUS_CODE: ClassVar[int] = (source)

Minimum valid HTTP status code.

Value
100
STATUS_COLORS: ClassVar[dict] = (source)

(bg_ansi, fg_ansi) tuples for HTTP status categories.

Value
{'1xx': (_BG_CYAN, _FG_BLACK),
 '2xx': (_BG_GREEN, _FG_WHITE),
 '3xx': (_BG_YELLOW, _FG_BLACK),
 '4xx': (_BG_MAGENTA, _FG_WHITE),
 '5xx': (_BG_RED, _FG_WHITE),
 'default': (_BG_GREY50, _FG_WHITE)}
__enabled: bool = (source)

Enable HTTP request printing to console by default.

__lifecycle_lock = (source)

Serialize worker startup and shutdown.

Async queue and worker task (initialized by start()).

__start_timer: ContextVar[float | None] = (source)

Context-local timestamp set by startTimer for each request.

__status_icons: dict[str, str] = (source)

Precompute status icons by HTTP code category.

__worker_task: asyncio.Task | None = (source)

Background task responsible for draining queued output.

Flush obtained from sys.stdout.flush.

_total_width = (source)

Total width produced by max.

LOAD_FAST vs sys.stdout LOAD_GLOBAL+LOAD_ATTR.