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

Undocumented

Method __buildBaseUrlASGI Build the base URL from an ASGI scope.
Method __buildBaseUrlRSGI Build the base URL from an RSGI scope.
Method __buildUrlASGI Build the full URL from an ASGI scope.
Method __buildUrlRSGI Build the full URL from an RSGI scope.
Method __contentType Parse and cache the request Content-Type header.
Method __getAcceptLower Cache and return the lowercased request Accept header.
Method __getBodyStream Create the body reader when the request consumes its body.
Method __getScope Materialize the transport scope on its first access.
Method __init__ Initialize an HTTP request from an interface, adapter, and body stream.
Async Method __parseDataJson Parse JSON body for data() and populate the JSON cache.
Async Method __parseDataMsgpack Parse MessagePack body for data().
Async Method __parseDataMultipart Parse multipart body for data() in a single pass.
Async Method __parseDataUrlencoded Parse URL-encoded body for data() with multi-value support.
Method accepts Check if the client accepts a specific MIME type.
Async Method body Return the full request body as bytes.
Method close Close uploaded files retained by the parsed multipart request.
Method csrfToken Return the CSRF token for the current request.
Async Method data Return a flat dictionary parsed from the request body.
Async Method form Parse multipart/form-data using a streaming parser.
Async Method formUrlEncoded Parse application/x-www-form-urlencoded body.
Method isAjax Determine if the request was made via AJAX.
Async Method json Parse the request body as JSON.
Async Method msgpack Decode the request body as MessagePack.
Async Method payload Parse and return structured data according to Content-Type.
Async Method raw Return the request body as raw bytes.
Method routeParam Return a specific path parameter by key.
Method routeParams Return all path parameters as a dictionary.
Async Method stream Yield chunks of the request body as they arrive.
Async Method text Decode the request body as UTF-8 text.
Method wantsHtml Determine if the client expects an HTML response based on the Accept header.
Method wantsJson Determine if the client prefers a JSON response based on the Accept header.
Method wantsXml Determine if the client prefers an XML response based on the Accept header.
Async Method xml Parse the request body as XML.
Class Variable __slots__ Undocumented
Class Variable csrf_token Undocumented
Instance Variable __adapter Undocumented
Instance Variable __body_limits Undocumented
Instance Variable __body_stream Undocumented
Instance Variable __cached_accept_lower Undocumented
Instance Variable __cached_base_url Undocumented
Instance Variable __cached_content_type Undocumented
Instance Variable __cached_cookies Undocumented
Instance Variable __cached_data Undocumented
Instance Variable __cached_form Undocumented
Instance Variable __cached_forwarded Undocumented
Instance Variable __cached_headers Undocumented
Instance Variable __cached_http_version Undocumented
Instance Variable __cached_ip Undocumented
Instance Variable __cached_json Undocumented
Instance Variable __cached_method Undocumented
Instance Variable __cached_multipart Undocumented
Instance Variable __cached_path Undocumented
Instance Variable __cached_port Undocumented
Instance Variable __cached_query_params Undocumented
Instance Variable __cached_scheme Undocumented
Instance Variable __cached_url Undocumented
Instance Variable __interface Undocumented
Instance Variable __json_parsed Undocumented
Instance Variable __path_params Undocumented
Instance Variable __receive_or_protocol Undocumented
Instance Variable __registry Undocumented
Instance Variable __scope Undocumented
Instance Variable __state Undocumented
Property accept Return the value of the Accept header.
Property apiKey Return the API key from the request headers if present.
Property authorization Return the Authorization header value if present.
Property baseUrl Return the base URL (scheme and host) for the request.
Property bearerToken Extract a bearer credential from one unambiguous Authorization header.
Property cookies Return parsed cookies from the request.
Property forwarded Return the forwarded information from the request scope.
Property headers Return the request headers as a Headers object.
Property httpVersion Return the HTTP version of the request.
Property interface Return the interface type of the request (ASGI or RSGI).
Property ip Return the client's IP address from the request scope.
Property method Return the HTTP request method.
Property path Return the request path.
Property port Return the client's port number from the request scope.
Property queryParams Return parsed query parameters from the request URL.
Property scheme Return the URL scheme (e.g., 'http' or 'https') of the request.
Property scope Return the raw ASGI / RSGI connection scope.
Property state Return the mutable request state namespace.
Property url Return the full request URL.
Property userAgent Return the User-Agent string from the request headers.
def __buildBaseUrlASGI(self) -> str: (source)

Build the base URL from an ASGI scope.

Constructs the base URL by combining scheme, host, and optional root_path from the ASGI scope.

Returns
strThe base URL (scheme://host or scheme://host/root_path).
def __buildBaseUrlRSGI(self) -> str: (source)

Build the base URL from an RSGI scope.

Returns the base URL composed of scheme and host.

Returns
strThe base URL (scheme://host).
def __buildUrlASGI(self) -> str: (source)

Build the full URL from an ASGI scope.

Constructs the complete request URL by combining scheme, host, path, and query string from the ASGI scope.

Returns
strThe constructed request URL.
def __buildUrlRSGI(self) -> str: (source)

Build the full URL from an RSGI scope.

Constructs the complete request URL by combining scheme, host, path, and query string from the RSGI scope.

Returns
strThe constructed request URL.
def __contentType(self) -> tuple[str, dict[str, str]]: (source)

Parse and cache the request Content-Type header.

Returns
tuple[str, dict[str, str]]Return the media type and parsed parameters from the Content-Type header.
def __getAcceptLower(self) -> str: (source)

Cache and return the lowercased request Accept header.

Returns
strReturn the lowercased Accept header value, or an empty string when the header is missing.
def __getBodyStream(self) -> IBodyStream: (source)

Create the body reader when the request consumes its body.

Returns
IBodyStreamBody reader shared by all payload parsing methods.
def __getScope(self) -> dict[str, Any]: (source)

Materialize the transport scope on its first access.

Returns
dict[str, Any]Request-local scope snapshot, retained for subsequent reads.
def __init__(self, interface: Interface, adapter: TransportAdapter, body_stream: IBodyStream | None = None, *, registry: MediaTypeRegistry | None = None, receive_or_protocol: object = None, params: Mapping[str, Any] | None = None, body_limits: HTTPBodyLimits | None = None): (source)

Initialize an HTTP request from an interface, adapter, and body stream.

Parameters
interface:InterfaceTransport protocol type (ASGI or RSGI).
adapter:TransportAdapterProvides the parsed scope dict and header accessor.
body_stream:IBodyStream | None, optionalPre-constructed stream, or None to create it on first body access.
registry:MediaTypeRegistry | None, optionalContent-type parser registry. Defaults to DEFAULT_MEDIA_TYPES.
receive_or_protocol:object, optionalASGI receive callable or RSGI protocol used for lazy body creation.
params:Mapping[str, Any] | None, optionalPath parameters extracted from the URL. Defaults to None.
body_limits:HTTPBodyLimits | None, optionalFinite request and multipart limits. Defaults to HTTPBodyLimits().
Returns
NoneUndocumented
async def __parseDataJson(self) -> dict[str, Any]: (source)

Parse JSON body for data() and populate the JSON cache.

Returns
dict[str, Any]Parsed JSON object from the request body.
Raises
ValueErrorIf the JSON body is empty or cannot be decoded.
TypeErrorIf the decoded JSON payload is not an object.
async def __parseDataMsgpack(self) -> dict[str, Any]: (source)

Parse MessagePack body for data().

Returns
dict[str, Any]Decoded MessagePack mapping.
Raises
ValueErrorIf the MessagePack payload cannot be decoded.
TypeErrorIf the decoded MessagePack payload is not a map.
async def __parseDataMultipart(self) -> dict[str, Any]: (source)

Parse multipart body for data() in a single pass.

Returns
dict[str, Any]Merged mapping of multipart fields and uploaded files.
async def __parseDataUrlencoded(self) -> dict[str, Any]: (source)

Parse URL-encoded body for data() with multi-value support.

Returns
dict[str, Any]Parsed form mapping where repeated keys are preserved as lists.
def accepts(self, mime: str) -> bool: (source)

Check if the client accepts a specific MIME type.

Parameters
mime:strThe MIME type to check.
Returns
boolTrue if the MIME type is present in the Accept header.
async def body(self) -> bytes: (source)

Return the full request body as bytes.

Buffers the stream on first call and caches the result. Subsequent calls are O(1) — they return the cached buffer.

Returns
bytesThe complete request body as bytes.
def close(self): (source)

Close uploaded files retained by the parsed multipart request.

Returns
NoneRelease upload handles after response delivery. Calling this method repeatedly is safe; background tasks must finish before closure.
def csrfToken(self) -> str | None: (source)

Return the CSRF token for the current request.

The token is set on request.state.csrf_token by CSRFTokenMiddleware before the route handler is called. Returns None when the middleware has not run (e.g. API routes).

Returns
str | NoneThe CSRF token, or None when not available.
async def data(self) -> dict[str, Any]: (source)

Return a flat dictionary parsed from the request body.

Cache the parsed value so repeated calls are O(1).

Parsing is selected by Content-Type:

  • application/json -> JSON object (must be a mapping)
  • application/x-www-form-urlencoded -> form fields with
    scalar-or-list collapsing for repeated keys
  • multipart/form-data -> text fields and uploaded files with the
    same scalar-or-list collapsing
  • application/msgpack -> MessagePack object (must be a mapping)
Returns
dict[str, Any]Flat dictionary suitable for downstream request validation.
Raises
UnsupportedMediaTypeExceptionRaise if Content-Type cannot be converted to a dictionary.
ValueErrorRaise if a JSON or MessagePack body is empty or cannot be decoded, or if multipart parsing fails.
TypeErrorRaise if decoded JSON or MessagePack content is not a mapping.
async def form(self) -> FormData: (source)

Parse multipart/form-data using a streaming parser.

The boundary is extracted with a proper RFC 2046-compatible parser, so quoted boundaries and extra parameters are handled correctly. The BodyStream provides transparent replay: if body() was called first, the buffer is streamed to the multipart parser instead of re-reading the transport.

Returns
FormDataParsed multipart form data. Result is cached.
Raises
UnsupportedMediaTypeExceptionIf the Content-Type is not multipart/form-data.
ValueErrorIf the multipart boundary is absent.
async def formUrlEncoded(self) -> dict[str, Any]: (source)

Parse application/x-www-form-urlencoded body.

Returns
dict[str, Any]Parsed form fields. Result is cached.
Raises
UnsupportedMediaTypeExceptionIf the Content-Type is not application/x-www-form-urlencoded.
def isAjax(self) -> bool: (source)

Determine if the request was made via AJAX.

Returns
boolTrue if the X-Requested-With header is 'XMLHttpRequest'.
async def json(self) -> object: (source)

Parse the request body as JSON.

Validates Content-Type, buffers the body, and delegates decoding to msgspec. Result is cached; a JSON null literal is handled correctly via the __json_parsed sentinel.

Returns
objectThe decoded JSON value: dict, list, str, int, float, bool, or None.
Raises
UnsupportedMediaTypeExceptionIf the Content-Type is not application/json (or a +json subtype).
ValueErrorIf the body is empty or not valid JSON.
async def msgpack(self) -> object: (source)

Decode the request body as MessagePack.

Returns
objectThe decoded MessagePack value, including maps, arrays, scalars, binary data, extension values, or None.
Raises
msgspec.DecodeErrorIf the payload is not valid MessagePack.
async def payload(self) -> object: (source)

Parse and return structured data according to Content-Type.

Dispatches to the registered BodyParser callable from MediaTypeRegistry. multipart/form-data is handled separately because it requires a streaming body, not a pre-buffered bytes value. Falls back to raw bytes when the media type is absent or not registered.

Returns
objectParsed body, or raw bytes when no parser matches.
async def raw(self) -> bytes: (source)

Return the request body as raw bytes.

Returns
bytesThe raw request body.
def routeParam(self, key: str) -> object: (source)

Return a specific path parameter by key.

Parameters
key:strThe specific path parameter key to retrieve.
Returns
objectConverted parameter value, or None when the key is absent.
def routeParams(self) -> dict[str, Any]: (source)

Return all path parameters as a dictionary.

Returns
dict[str, Any]A dictionary of all path parameters.
async def stream(self) -> AsyncGenerator[bytes]: (source)

Yield chunks of the request body as they arrive.

Delegates to BodyStream, which handles RSGI and ASGI transports, enforces max_body_size, and replays from the internal buffer when the body has already been fully read by body() or a parser.

Returns
AsyncGenerator[bytes]Yields chunks of the request body as bytes.
async def text(self) -> str: (source)

Decode the request body as UTF-8 text.

Returns
strThe decoded request body.
def wantsHtml(self) -> bool: (source)

Determine if the client expects an HTML response based on the Accept header.

Returns
boolTrue if the Accept header indicates HTML is expected.
def wantsJson(self) -> bool: (source)

Determine if the client prefers a JSON response based on the Accept header.

Returns
boolTrue if the Accept header contains application/json or any +json subtype.
def wantsXml(self) -> bool: (source)

Determine if the client prefers an XML response based on the Accept header.

Returns
boolTrue if the Accept header indicates XML is preferred.
async def xml(self) -> XMLElement: (source)

Parse the request body as XML.

Uses defusedxml to reject internal and external entity declarations. DTDs without entity declarations are allowed; external resources are not resolved.

Returns
XMLElement (xml.etree.ElementTree.Element)Root element of the parsed XML document.
Raises
xml.etree.ElementTree.ParseErrorIf the payload is malformed XML.
defusedxml.common.EntitiesForbiddenIf the document declares an internal or external entity. This is a subclass of defusedxml.common.DefusedXmlException, not ParseError.
__adapter = (source)

Undocumented

__body_limits = (source)

Undocumented

__body_stream: IBodyStream | None = (source)

Undocumented

__cached_accept_lower = (source)

Undocumented

__cached_base_url = (source)

Undocumented

__cached_content_type = (source)

Undocumented

__cached_cookies = (source)

Undocumented

__cached_data: dict[str, Any] | None = (source)

Undocumented

__cached_form = (source)

Undocumented

__cached_forwarded = (source)

Undocumented

__cached_headers = (source)

Undocumented

__cached_http_version = (source)

Undocumented

__cached_ip = (source)

Undocumented

__cached_json = (source)

Undocumented

__cached_method = (source)

Undocumented

__cached_multipart = (source)

Undocumented

__cached_path = (source)

Undocumented

__cached_port = (source)

Undocumented

__cached_query_params = (source)

Undocumented

__cached_scheme = (source)

Undocumented

__cached_url: str | None = (source)

Undocumented

__interface = (source)

Undocumented

__json_parsed: bool = (source)

Undocumented

__path_params: dict[str, Any] | None = (source)

Undocumented

__receive_or_protocol = (source)

Undocumented

__registry: MediaTypeRegistry = (source)

Undocumented

__scope: dict[str, Any] | None = (source)

Undocumented

__state: SimpleNamespace | None = (source)

Undocumented

Return the value of the Accept header.

Returns
str | NoneThe value of the 'Accept' header, or None if not present.

Return the API key from the request headers if present.

Returns
str | NoneThe API key from the 'X-API-Key' header, or None if not present.
authorization: str | None = (source)

Return the Authorization header value if present.

Returns
str | NoneThe value of the 'Authorization' header, or None if not present.

Return the base URL (scheme and host) for the request.

Returns
strBase URL composed of scheme, host, and optional root_path. Result is cached after the first call.
bearerToken: str | None = (source)

Extract a bearer credential from one unambiguous Authorization header.

Returns
str | NoneToken after a case-insensitive Bearer scheme, with surrounding whitespace removed. Missing, empty or duplicate headers return None.
cookies: Cookies = (source)

Return parsed cookies from the request.

Returns
CookiesThe parsed cookies as a Cookies object.
forwarded: dict[str, Any] = (source)

Return the forwarded information from the request scope.

Returns
dict[str, Any]The forwarded information as a dictionary.
headers: Headers = (source)

Return the request headers as a Headers object.

Returns
HeadersThe headers associated with the request.
httpVersion: str = (source)

Return the HTTP version of the request.

Returns
strThe HTTP version string, such as '1.1' or '2'.
interface: Interface = (source)

Return the interface type of the request (ASGI or RSGI).

Returns
InterfaceThe interface type of the request.

Return the client's IP address from the request scope.

After the ProxiesMiddleware runs, the adapter always stores the normalized plain-string IP in the scope via setState. For ASGI without proxy middleware, the original (host, port) tuple is handled as a fallback.

Returns
str | NoneThe client's IP address if available, otherwise None.

Return the HTTP request method.

Returns
strThe HTTP method of the request, such as 'GET' or 'POST'.

Return the request path.

Returns
strThe path component of the request URL.

Return the client's port number from the request scope.

Returns
int | NoneThe client's port number if available, otherwise None.
queryParams: QueryParams = (source)

Return parsed query parameters from the request URL.

Returns
QueryParamsParsed query parameters. Result is cached after the first call.

Return the URL scheme (e.g., 'http' or 'https') of the request.

Returns
strThe URL scheme of the request.

Return the raw ASGI / RSGI connection scope.

Exposes the underlying scope dict so that ASGI-aware middleware, tracing libraries, and extensions can read or annotate transport-level data without requiring framework-specific adapters.

Returns
dict[str, Any]The raw scope dictionary provided by the transport layer.
state: SimpleNamespace = (source)

Return the mutable request state namespace.

Middleware and handlers can attach arbitrary attributes to this namespace without polluting the scope dict. Modelled after Starlette's request.state.

Returns
types.SimpleNamespaceThe mutable state object for this request.

Return the full request URL.

Returns
strAbsolute URL including scheme, host, path, and query string. Result is cached after the first call.

Return the User-Agent string from the request headers.

Returns
str | NoneThe User-Agent string if present, otherwise None.