Module

http.request

Immutable HTTP request.

Frozen metadata with async body access. The request is honest about what it is: received data that doesn't change.

Classes

Request 26
An immutable HTTP request. Metadata (method, path, headers, etc.) is frozen at creation. Body is a…

An immutable HTTP request.

Metadata (method, path, headers, etc.) is frozen at creation. Body is accessed asynchronously via.body(), .json(), .form().

Cookies are parsed once at creation time (infrom_asgi) and stored as a frozen field — not re-parsed on every access.

Attributes

Name Type Description
method str
path str
headers Headers
query QueryParams
path_params dict[str, str]
http_version str
server tuple[str, int] | None
client tuple[str, int] | None
cookies Mapping[str, str]
_receive Receive
_cache dict[str, Any]

Methods

is_fragment 0 bool
True if this is an htmx fragment request (HX-Request header).
property
def is_fragment(self) -> bool
Returns
bool
is_history_restore 0 bool
True if htmx is restoring from history (cache miss on back/forward).
property
def is_history_restore(self) -> bool
Returns
bool
is_boosted 0 bool
True if this request came from an hx-boost enhanced element.
property
def is_boosted(self) -> bool
Returns
bool
htmx_target 0 str | None
The target element ID from HX-Target header.
property
def htmx_target(self) -> str | None
Returns
str | None
htmx_trigger 0 str | None
The trigger element ID from HX-Trigger header.
property
def htmx_trigger(self) -> str | None
Returns
str | None
htmx_trigger_name 0 str | None
The name attribute of the trigger element (HX-Trigger-Name header).
property
def htmx_trigger_name(self) -> str | None
Returns
str | None
content_type 0 str | None
The Content-Type header value.
property
def content_type(self) -> str | None
Returns
str | None
content_length 0 int | None
The Content-Length header as int.
property
def content_length(self) -> int | None
Returns
int | None
url 0 str
Full request URL (path + query string).
property
def url(self) -> str
Returns
str
body 0 bytes
Read the full request body. Result is cached — the ASGI receive is consumed on…
async
async def body(self) -> bytes

Read the full request body.

Result is cached — the ASGI receive is consumed once, then the same bytes are returned on subsequent calls.

Returns
bytes
stream 0 AsyncGenerator[bytes]
Stream the request body in chunks.
async
async def stream(self) -> AsyncGenerator[bytes]
Returns
AsyncGenerator[bytes]
json 0 Any
Parse the body as JSON.
async
async def json(self) -> Any
Returns
Any
text 0 str
Read the body as text (UTF-8).
async
async def text(self) -> str
Returns
str
form 0 FormData
Parse the body as form data (URL-encoded or multipart). Result is cached — the…
async
async def form(self) -> FormData

Parse the body as form data (URL-encoded or multipart).

Result is cached — the body is read and parsed once, then the sameFormDatais returned on subsequent calls.

Supportsapplication/x-www-form-urlencoded(stdlib) and multipart/form-data (requires pip install chirp[forms]).

Returns
FormData Parsed ``FormData`` implementing ``MultiValueMapping``.
from_asgi 3 Request
Create a Request from an ASGI scope and receive callable.
classmethod
def from_asgi(cls, scope: dict[str, Any], receive: Receive, path_params: dict[str, str] | None = None) -> Request
Parameters
Name Type Description
scope
receive
path_params Default:None
Returns
Request