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 Response(_FlashData, IResponse): (source)
Known subclasses: orionis.http.HTMLResponse, orionis.http.JSONResponse, orionis.http.PlainTextResponse, orionis.http.RedirectResponse, orionis.http.StreamingResponse
Constructor: Response(content, status_code, headers, media_type, ...)
Represent an HTTP response with status, headers, cookies and body.
| Method | __init__ |
Initialize the BaseResponse object. |
| Method | add |
Add a header to the response. |
| Method | delete |
Delete a cookie by setting its expiration to the past. |
| Method | get |
Return the response body as bytes. |
| Method | get |
Return the data queued by withFlash() for the session flash bag. |
| Method | get |
Get the values for a header. |
| Method | get |
Return the media type of the response. |
| Method | get |
Return the headers as a list of (key, value) byte tuples. |
| Method | get |
Return the HTTP status code of the response. |
| Method | get |
Return the response stream if present. |
| Method | get |
Return the headers as a list of (key, value) string tuples. |
| Method | has |
Check if a header is present. |
| Method | has |
Check if the response has a stream. |
| Method | remove |
Remove a header from the response. |
| Method | render |
Render the content to bytes. |
| Async Method | run |
Run the background task if it exists. |
| Method | set |
Set a cookie header in the response. |
| Method | set |
Set a header, replacing any existing values. |
| Method | with |
Set the background task and return the response. |
| Method | with |
Attach a cookie and return the response for chaining. |
| Method | with |
Attach several cookies at once and return the response. |
| Method | with |
Merge response headers and return the response. |
| Method | without |
Expire a cookie and return the response for chaining. |
| Method | with |
Set the HTTP status code and return the response. |
| Class Variable | __slots__ |
Declare the instance attribute slots reserved by this class. |
| Class Variable | charset |
Encode text responses using UTF-8. |
| Instance Variable | _body |
HTTP response body or encoded payload returned to the client. |
| Instance Variable | _flash |
Initialize flash data when it is first queued. |
| Instance Variable | _headers |
The headers to include in the response. |
| Instance Variable | _raw |
Protocol-ready header pairs emitted with the response. |
| Instance Variable | _stream |
Iterator supplying response body chunks. |
| Instance Variable | background |
The background task to run after response. |
| Instance Variable | media |
The media type of the response. |
| Instance Variable | status |
The HTTP status code for the response. |
Inherited from _FlashData:
| Method | with |
Flash validation errors for the next request. |
| Method | with |
Queue a status message for the owning response or pending view. |
| Method | with |
Flash the submitted payload so the next request can repopulate it. |
Self, content: Any | None = None, status_code: HTTPStatus | int = 200, headers: Mapping[ str, str] | None = None, media_type: str | None = None, background: BackgroundTask | None = None):
(source)
¶
orionis.http.HTMLResponse, orionis.http.JSONResponse, orionis.http.PlainTextResponse, orionis.http.RedirectResponse, orionis.http.StreamingResponseInitialize the BaseResponse object.
| Parameters | |
content:typing.Any, optional | The response content or stream. |
statusorionis.http.enums.HTTPStatus | int, optional | The HTTP status code for the response. |
headers:collections.abc.Mapping[str, str] | None, optional | The headers to include in the response. |
mediastr | None, optional | The media type of the response. |
background:orionis.background.BackgroundTask | None, optional | The background task to run after response. |
| Returns | |
None | This method does not return a value. |
Return the response body as bytes.
| Returns | |
bytes | None | The response body as bytes, or None if not set. |
Return the data queued by withFlash() for the session flash bag.
| Returns | |
dict[str, typing.Any] | None | The queued key-value pairs, or None when nothing was queued. |
orionis.http.EventStreamResponseReturn the response stream if present.
| Returns | |
collections.abc.AsyncIterable[bytes] | None | The response stream, or None if not set. |
orionis.http.JSONResponseRender the content to bytes.
| Parameters | |
content:typing.Any | The content to render. |
| Returns | |
bytes | The rendered content as bytes. |
Self, key: str, value: str = '', *, max_age: int | None = None, expires: datetime | str | int | None = None, path: str | None = '/', domain: str | None = None, secure: bool = False, http_only: bool = False, same_site: Literal[ 'lax', 'strict', 'none'] | None = 'lax', partitioned: bool = False):
(source)
¶
Set a cookie header in the response.
| Parameters | |
key:str | The cookie name. |
value:str, optional | The cookie value. Defaults to an empty string. |
maxint | None, optional | The maximum age of the cookie in seconds. |
expires:datetime.datetime | str | int | None, optional | The expiration date of the cookie. |
path:str | None, optional | The path for which the cookie is valid. |
domain:str | None, optional | The domain for which the cookie is valid. |
secure:bool, optional | Whether the cookie is secure. |
httpbool, optional | Whether the cookie is HTTP only. |
samestr | None, optional | The SameSite policy for the cookie. |
partitioned:bool, optional | Whether the cookie is partitioned. |
| Returns | |
None | This method does not return a value. |
Set the background task and return the response.
| Parameters | |
background:orionis.background.BackgroundTask | None | Task to run after the response is sent, or None to clear it. |
| Returns | |
typing.Self | The same response, enabling fluent chaining. |
| Raises | |
TypeError | If background is neither a background task nor None. |
Self, key: str, value: str = '', *, max_age: int | None = None, expires: datetime | str | int | None = None, path: str | None = '/', domain: str | None = None, secure: bool = False, http_only: bool = False, same_site: Literal[ 'lax', 'strict', 'none'] | None = 'lax', partitioned: bool = False) -> Self:
(source)
¶
Attach a cookie and return the response for chaining.
| Parameters | |
key:str | The cookie name. |
value:str, optional | The cookie value. Defaults to an empty string. |
maxint | None, optional | The maximum age of the cookie in seconds. |
expires:datetime.datetime | str | int | None, optional | The expiration date of the cookie. |
path:str | None, optional | The path for which the cookie is valid. |
domain:str | None, optional | The domain for which the cookie is valid. |
secure:bool, optional | Whether the cookie is secure. |
httpbool, optional | Whether the cookie is HTTP only. |
samestr | None, optional | The SameSite policy for the cookie. |
partitioned:bool, optional | Whether the cookie is partitioned. |
| Returns | |
typing.Self | The same response instance, allowing fluent chaining. |
Attach several cookies at once and return the response.
| Parameters | |
cookies:typing.Mapping[str, str | typing.Mapping[str, typing.Any]] | Mapping of cookie names to either a plain value or a mapping of
keyword arguments accepted by orionis.http.Response.setCookie. |
| Returns | |
typing.Self | The same response instance, allowing fluent chaining. |
Merge response headers and return the response.
Replace existing values for each supplied name without changing unrelated headers. Header names are compared without regard to case.
| Parameters | |
headers:collections.abc.Mapping[str, str] | Header names and values to apply through setHeader(). |
| Returns | |
typing.Self | The same response, enabling fluent chaining. |
| Raises | |
TypeError | If headers is not a mapping. |
Self, key: str, *, path: str = '/', domain: str | None = None) -> Self:
(source)
¶
Expire a cookie and return the response for chaining.
| Parameters | |
key:str | The name of the cookie to delete. |
path:str, default "/" | The path for which the cookie is valid. |
domain:str | None, optional | The domain for which the cookie is valid. |
| Returns | |
typing.Self | The same response instance, allowing fluent chaining. |
orionis.http.RedirectResponseSet the HTTP status code and return the response.
| Parameters | |
statusorionis.http.enums.HTTPStatus | int | HTTP status code between 100 and 599. |
| Returns | |
typing.Self | The same response, enabling fluent chaining. |
| Raises | |
TypeError | If status_code is not an integer. |
ValueError | If status_code is outside the accepted HTTP range. |
orionis.http.HTMLResponse, orionis.http.JSONResponse, orionis.http.PlainTextResponse, orionis.http.RedirectResponse, orionis.http.StreamingResponseDeclare the instance attribute slots reserved by this class.
orionis.http.StreamingResponseHTTP response body or encoded payload returned to the client.