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 Request(IRequest): (source)
Constructor: Request(interface, adapter, body_stream, registry, ...)
Undocumented
| Method | __build |
Build the base URL from an ASGI scope. |
| Method | __build |
Build the base URL from an RSGI scope. |
| Method | __build |
Build the full URL from an ASGI scope. |
| Method | __build |
Build the full URL from an RSGI scope. |
| Method | __content |
Parse and cache the request Content-Type header. |
| Method | __get |
Cache and return the lowercased request Accept header. |
| Method | __get |
Create the body reader when the request consumes its body. |
| Method | __get |
Materialize the transport scope on its first access. |
| Method | __init__ |
Initialize an HTTP request from an interface, adapter, and body stream. |
| Async Method | __parse |
Parse JSON body for data() and populate the JSON cache. |
| Async Method | __parse |
Parse MessagePack body for data(). |
| Async Method | __parse |
Parse multipart body for data() in a single pass. |
| Async Method | __parse |
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 | csrf |
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 | form |
Parse application/x-www-form-urlencoded body. |
| Method | is |
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 | route |
Return a specific path parameter by key. |
| Method | route |
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 | wants |
Determine if the client expects an HTML response based on the Accept header. |
| Method | wants |
Determine if the client prefers a JSON response based on the Accept header. |
| Method | wants |
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 |
Undocumented |
| Instance Variable | __adapter |
Undocumented |
| Instance Variable | __body |
Undocumented |
| Instance Variable | __body |
Undocumented |
| Instance Variable | __cached |
Undocumented |
| Instance Variable | __cached |
Undocumented |
| Instance Variable | __cached |
Undocumented |
| Instance Variable | __cached |
Undocumented |
| Instance Variable | __cached |
Undocumented |
| Instance Variable | __cached |
Undocumented |
| Instance Variable | __cached |
Undocumented |
| Instance Variable | __cached |
Undocumented |
| Instance Variable | __cached |
Undocumented |
| Instance Variable | __cached |
Undocumented |
| Instance Variable | __cached |
Undocumented |
| Instance Variable | __cached |
Undocumented |
| Instance Variable | __cached |
Undocumented |
| Instance Variable | __cached |
Undocumented |
| Instance Variable | __cached |
Undocumented |
| Instance Variable | __cached |
Undocumented |
| Instance Variable | __cached |
Undocumented |
| Instance Variable | __cached |
Undocumented |
| Instance Variable | __interface |
Undocumented |
| Instance Variable | __json |
Undocumented |
| Instance Variable | __path |
Undocumented |
| Instance Variable | __receive |
Undocumented |
| Instance Variable | __registry |
Undocumented |
| Instance Variable | __scope |
Undocumented |
| Instance Variable | __state |
Undocumented |
| Property | accept |
Return the value of the Accept header. |
| Property | api |
Return the API key from the request headers if present. |
| Property | authorization |
Return the Authorization header value if present. |
| Property | base |
Return the base URL (scheme and host) for the request. |
| Property | bearer |
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 | http |
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 | query |
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 | user |
Return the User-Agent string from the request headers. |
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 | |
str | The base URL (scheme://host or scheme://host/root_path). |
Build the base URL from an RSGI scope.
Returns the base URL composed of scheme and host.
| Returns | |
str | The base URL (scheme://host). |
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 | |
str | The constructed request URL. |
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 | |
str | The constructed request URL. |
Cache and return the lowercased request Accept header.
| Returns | |
str | Return the lowercased Accept header value, or an empty string when the header is missing. |
Create the body reader when the request consumes its body.
| Returns | |
IBodyStream | Body reader shared by all payload parsing methods. |
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:Interface | Transport protocol type (ASGI or RSGI). |
adapter:TransportAdapter | Provides the parsed scope dict and header accessor. |
bodyIBodyStream | None, optional | Pre-constructed stream, or None to create it on first body access. |
registry:MediaTypeRegistry | None, optional | Content-type parser registry. Defaults to DEFAULT_MEDIA_TYPES. |
receiveobject, optional | ASGI receive callable or RSGI protocol used for lazy body creation. |
params:Mapping[str, Any] | None, optional | Path parameters extracted from the URL. Defaults to None. |
bodyHTTPBodyLimits | None, optional | Finite request and multipart limits. Defaults to HTTPBodyLimits(). |
| Returns | |
None | Undocumented |
Parse JSON body for data() and populate the JSON cache.
| Returns | |
dict[str, Any] | Parsed JSON object from the request body. |
| Raises | |
ValueError | If the JSON body is empty or cannot be decoded. |
TypeError | If the decoded JSON payload is not an object. |
Parse MessagePack body for data().
| Returns | |
dict[str, Any] | Decoded MessagePack mapping. |
| Raises | |
ValueError | If the MessagePack payload cannot be decoded. |
TypeError | If the decoded MessagePack payload is not a map. |
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 | |
bytes | The complete request body as bytes. |
Close uploaded files retained by the parsed multipart request.
| Returns | |
None | Release upload handles after response delivery. Calling this method repeatedly is safe; background tasks must finish before closure. |
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 | None | The CSRF token, or None when not available. |
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 | |
UnsupportedMediaTypeException | Raise if Content-Type cannot be converted to a dictionary. |
ValueError | Raise if a JSON or MessagePack body is empty or cannot be decoded, or if multipart parsing fails. |
TypeError | Raise if decoded JSON or MessagePack content is not a mapping. |
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 | |
FormData | Parsed multipart form data. Result is cached. |
| Raises | |
UnsupportedMediaTypeException | If the Content-Type is not multipart/form-data. |
ValueError | If the multipart boundary is absent. |
Determine if the request was made via AJAX.
| Returns | |
bool | True if the X-Requested-With header is 'XMLHttpRequest'. |
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 | |
object | The decoded JSON value: dict, list, str, int, float, bool, or None. |
| Raises | |
UnsupportedMediaTypeException | If the Content-Type is not application/json (or a +json subtype). |
ValueError | If the body is empty or not valid JSON. |
Decode the request body as MessagePack.
| Returns | |
object | The decoded MessagePack value, including maps, arrays, scalars, binary data, extension values, or None. |
| Raises | |
msgspec.DecodeError | If the payload is not valid MessagePack. |
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 | |
object | Parsed body, or raw bytes when no parser matches. |
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. |
Determine if the client expects an HTML response based on the Accept header.
| Returns | |
bool | True if the Accept header indicates HTML is expected. |
Determine if the client prefers a JSON response based on the Accept header.
| Returns | |
bool | True if the Accept header contains application/json or any +json subtype. |
Determine if the client prefers an XML response based on the Accept header.
| Returns | |
bool | True if the Accept header indicates XML is preferred. |
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.ParseError | If the payload is malformed XML. |
defusedxml.common.EntitiesForbidden | If the document declares an internal or external entity. This is a subclass of defusedxml.common.DefusedXmlException, not ParseError. |
Return the value of the Accept header.
| Returns | |
str | None | The value of the 'Accept' header, or None if not present. |
Return the API key from the request headers if present.
| Returns | |
str | None | The API key from the 'X-API-Key' header, or None if not present. |
Return the Authorization header value if present.
| Returns | |
str | None | The value of the 'Authorization' header, or None if not present. |
Return the base URL (scheme and host) for the request.
| Returns | |
str | Base URL composed of scheme, host, and optional root_path. Result is cached after the first call. |
Extract a bearer credential from one unambiguous Authorization header.
| Returns | |
str | None | Token after a case-insensitive Bearer scheme, with surrounding whitespace removed. Missing, empty or duplicate headers return None. |
Return the request headers as a Headers object.
| Returns | |
Headers | The headers associated with the request. |
Return the interface type of the request (ASGI or RSGI).
| Returns | |
Interface | The 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 | None | The client's IP address if available, otherwise None. |
Return the client's port number from the request scope.
| Returns | |
int | None | The client's port number if available, otherwise None. |
Return parsed query parameters from the request URL.
| Returns | |
QueryParams | Parsed query parameters. Result is cached after the first call. |
Return the URL scheme (e.g., 'http' or 'https') of the request.
| Returns | |
str | The 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. |
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.SimpleNamespace | The mutable state object for this request. |
Return the full request URL.
| Returns | |
str | Absolute URL including scheme, host, path, and query string. Result is cached after the first call. |