Classes
RequestUrlScope
3
▼
Request-local public URL prefix.
Middleware can attach this to a copied ``Request`` when the app r…
RequestUrlScope
3
▼
Request-local public URL prefix.
Middleware can attach this to a copiedRequestwhen the app routes a
local path through a tenant or base-path public URL. It applies only to
app-root paths, leaving external URLs, anchors, and relative paths alone.
Attributes
| Name | Type | Description |
|---|---|---|
prefix |
str
|
— |
Methods
apply
1
str
▼
Return ``path`` under this request scope when it is app-rooted.
apply
1
str
▼
def apply(self, path: str) -> str
Parameters
| Name | Type | Description |
|---|---|---|
path |
— |
Returns
str
Internal Methods 1 ▼
__post_init__
0
▼
__post_init__
0
▼
def __post_init__(self) -> None
HtmxDetails
16
▼
Parsed htmx request headers with caching.
Attached to ``request.htmx``. Truthy when ``HX-Request``…
HtmxDetails
16
▼
Parsed htmx request headers with caching.
Attached torequest.htmx. Truthy when HX-Requestis present,
providing typed access to all htmx request headers. Values are
computed once and cached for the lifetime of the request.
Attributes
| Name | Type | Description |
|---|---|---|
_headers |
Headers
|
— |
_server |
tuple[str, int] | None
|
— |
_cache |
dict[str, str | None]
|
— |
Methods
boosted
0
bool
▼
True if this request came from an hx-boost enhanced element.
property
boosted
0
bool
▼
def boosted(self) -> bool
Returns
bool
history_restore
0
bool
▼
True if htmx is restoring from history (cache miss on back/forward).
property
history_restore
0
bool
▼
def history_restore(self) -> bool
Returns
bool
target
0
str | None
▼
The target element ID from HX-Target header.
property
target
0
str | None
▼
def target(self) -> str | None
Returns
str | None
target_id
0
str | None
▼
HX-Target normalized to a bare DOM id (no leading ``#``).
Canonical form for r…
property
target_id
0
str | None
▼
def target_id(self) -> str | None
HX-Target normalized to a bare DOM id (no leading#).
Canonical form for registry lookups and layout-chain matching.
ReturnsNonewhen HX-Target is absent or reduces to empty
after stripping (e.g. a bare#).
Returns
str | None
trigger
0
str | None
▼
The trigger element ID from HX-Trigger header.
property
trigger
0
str | None
▼
def trigger(self) -> str | None
Returns
str | None
trigger_name
0
str | None
▼
The name attribute of the trigger element (HX-Trigger-Name header).
property
trigger_name
0
str | None
▼
def trigger_name(self) -> str | None
Returns
str | None
current_url
0
str | None
▼
The browser's current URL from HX-Current-URL header.
property
current_url
0
str | None
▼
def current_url(self) -> str | None
Returns
str | None
current_url_abs_path
0
str | None
▼
The path portion of the browser's current URL.
Strips scheme and host when the…
property
current_url_abs_path
0
str | None
▼
def current_url_abs_path(self) -> str | None
The path portion of the browser's current URL.
Strips scheme and host when the origin matches this request's server, returning just the path (+ query + fragment). Returns the full URL unchanged when the origin differs or server info is unavailable.
Returns
str | None
prompt
0
str | None
▼
The user response to hx-prompt (HX-Prompt header).
property
prompt
0
str | None
▼
def prompt(self) -> str | None
Returns
str | None
partial
0
str | None
▼
The partial element name from HX-Partial header (htmx 4.0+).
Set when the requ…
property
partial
0
str | None
▼
def partial(self) -> str | None
The partial element name from HX-Partial header (htmx 4.0+).
Set when the request originates from an<htmx-partial>element.
Returns
str | None
Internal Methods 3 ▼
__init__
2
▼
__init__
2
▼
def __init__(self, headers: Headers, server: tuple[str, int] | None) -> None
Parameters
| Name | Type | Description |
|---|---|---|
headers |
— |
|
server |
— |
__bool__
0
bool
▼
True if this is an htmx request (HX-Request header is present).
__bool__
0
bool
▼
def __bool__(self) -> bool
Returns
bool
_get
1
str | None
▼
Read an htmx header with URI-AutoEncoded decoding and caching.
_get
1
str | None
▼
def _get(self, name: str) -> str | None
Parameters
| Name | Type | Description |
|---|---|---|
name |
— |
Returns
str | None
_LazyQueryParams
11
▼
QueryParams that parses on first access.
_LazyQueryParams
11
▼
QueryParams that parses on first access.
Methods
get
2
str | None
▼
get
2
str | None
▼
def get(self, key: str, default: None = None) -> str | None
Parameters
| Name | Type | Description |
|---|---|---|
key |
— |
|
default |
— |
Default:None
|
Returns
str | None
get
2
str | T
▼
get
2
str | T
▼
def get(self, key: str, default: T) -> str | T
Parameters
| Name | Type | Description |
|---|---|---|
key |
— |
|
default |
— |
Returns
str | T
get
2
object
▼
get
2
object
▼
def get(self, key: str, default: object = None) -> object
Parameters
| Name | Type | Description |
|---|---|---|
key |
— |
|
default |
— |
Default:None
|
Returns
object
get_list
1
list[str]
▼
get_list
1
list[str]
▼
def get_list(self, key: str) -> list[str]
Parameters
| Name | Type | Description |
|---|---|---|
key |
— |
Returns
list[str]
get_int
2
int | None
▼
get_int
2
int | None
▼
def get_int(self, key: str, default: int | None = None) -> int | None
Parameters
| Name | Type | Description |
|---|---|---|
key |
— |
|
default |
— |
Default:None
|
Returns
int | None
get_bool
2
bool | None
▼
get_bool
2
bool | None
▼
def get_bool(self, key: str, default: bool | None = None) -> bool | None
Parameters
| Name | Type | Description |
|---|---|---|
key |
— |
|
default |
— |
Default:None
|
Returns
bool | None
Internal Methods 5 ▼
__init__
1
▼
__init__
1
▼
def __init__(self, raw: bytes) -> None
Parameters
| Name | Type | Description |
|---|---|---|
raw |
— |
__getitem__
1
str
▼
__getitem__
1
str
▼
def __getitem__(self, key: str) -> str
Parameters
| Name | Type | Description |
|---|---|---|
key |
— |
Returns
str
__contains__
1
bool
▼
__contains__
1
bool
▼
def __contains__(self, key: object) -> bool
Parameters
| Name | Type | Description |
|---|---|---|
key |
— |
Returns
bool
__iter__
0
Iterator[str]
▼
__iter__
0
Iterator[str]
▼
def __iter__(self) -> Iterator[str]
Returns
Iterator[str]
__len__
0
int
▼
__len__
0
int
▼
def __len__(self) -> int
Returns
int
_LazyCookies
8
▼
Cookies that parse on first access.
_LazyCookies
8
▼
Cookies that parse on first access.
Methods
get
2
str | None
▼
get
2
str | None
▼
def get(self, key: str, default: None = None) -> str | None
Parameters
| Name | Type | Description |
|---|---|---|
key |
— |
|
default |
— |
Default:None
|
Returns
str | None
get
2
str | T
▼
get
2
str | T
▼
def get(self, key: str, default: T) -> str | T
Parameters
| Name | Type | Description |
|---|---|---|
key |
— |
|
default |
— |
Returns
str | T
get
2
object
▼
get
2
object
▼
def get(self, key: str, default: object = None) -> object
Parameters
| Name | Type | Description |
|---|---|---|
key |
— |
|
default |
— |
Default:None
|
Returns
object
Internal Methods 5 ▼
__init__
1
▼
__init__
1
▼
def __init__(self, cookie_header: str) -> None
Parameters
| Name | Type | Description |
|---|---|---|
cookie_header |
— |
__getitem__
1
str
▼
__getitem__
1
str
▼
def __getitem__(self, key: str) -> str
Parameters
| Name | Type | Description |
|---|---|---|
key |
— |
Returns
str
__contains__
1
bool
▼
__contains__
1
bool
▼
def __contains__(self, key: object) -> bool
Parameters
| Name | Type | Description |
|---|---|---|
key |
— |
Returns
bool
__iter__
0
Iterator[str]
▼
__iter__
0
Iterator[str]
▼
def __iter__(self) -> Iterator[str]
Returns
Iterator[str]
__len__
0
int
▼
__len__
0
int
▼
def __len__(self) -> int
Returns
int
Request
39
▼
An immutable HTTP request.
Metadata (method, path, headers, etc.) is frozen at creation.
Body is a…
Request
39
▼
An immutable HTTP request.
Metadata (method, path, headers, etc.) is frozen at creation.
Body is accessed asynchronously via.body(), .json(), .form().
Query params and cookies are parsed lazily on first access (not at creation).
Attributes
| Name | Type | Description |
|---|---|---|
method |
str
|
— |
path |
str
|
— |
headers |
Headers
|
— |
query |
QueryParams | _LazyQueryParams
|
— |
path_params |
dict[str, str]
|
— |
http_version |
str
|
— |
server |
tuple[str, int] | None
|
— |
client |
tuple[str, int] | None
|
— |
cookies |
Mapping[str, str] | _LazyCookies
|
— |
request_id |
str
|
— |
_receive |
Receive
|
— |
url_scope |
RequestUrlScope | None
|
— |
_url_for |
Callable[..., str] | None
|
— |
_cache |
dict[str, Any]
|
— |
Methods
htmx
0
HtmxDetails
▼
Typed, cached htmx request details.
Truthy when ``HX-Request`` is present::
…
property
htmx
0
HtmxDetails
▼
def htmx(self) -> HtmxDetails
Typed, cached htmx request details.
Truthy whenHX-Requestis present::
if request.htmx:
target = request.htmx.target
Returns
HtmxDetails
is_htmx
0
bool
▼
True if this is any htmx request (HX-Request header present).
property
is_htmx
0
bool
▼
def is_htmx(self) -> bool
Returns
bool
is_narrow_fragment
0
bool
▼
True if this htmx request targets a narrow fragment swap.
False for boosted na…
property
is_narrow_fragment
0
bool
▼
def is_narrow_fragment(self) -> bool
True if this htmx request targets a narrow fragment swap.
False for boosted navigations and history restores, which need full page content despite using htmx transport.
Returns
bool
is_fragment
0
bool
▼
True if this is an htmx request (HX-Request header).
.. deprecated::
Use `…
property
is_fragment
0
bool
▼
def is_fragment(self) -> bool
True if this is an htmx request (HX-Request header).
.. deprecated::
Useis_htmx (any htmx request) or is_narrow_fragment
(narrow fragment swap, excludes boosted and history restore).
Returns
bool
is_history_restore
0
bool
▼
True if htmx is restoring from history (cache miss on back/forward).
property
is_history_restore
0
bool
▼
def is_history_restore(self) -> bool
Returns
bool
is_boosted
0
bool
▼
True if this request came from an hx-boost enhanced element.
property
is_boosted
0
bool
▼
def is_boosted(self) -> bool
Returns
bool
htmx_target
0
str | None
▼
The target element ID from HX-Target header.
property
htmx_target
0
str | None
▼
def htmx_target(self) -> str | None
Returns
str | None
htmx_target_id
0
str | None
▼
HX-Target normalized to a bare DOM id (no leading ``#``).
Canonical form used …
property
htmx_target_id
0
str | None
▼
def htmx_target_id(self) -> str | None
HX-Target normalized to a bare DOM id (no leading#).
Canonical form used throughout the framework's request → registry
pipeline. Callers should prefer this overhtmx_targetunless
they specifically need the raw header value.
Returns
str | None
htmx_trigger
0
str | None
▼
The trigger element ID from HX-Trigger header.
property
htmx_trigger
0
str | None
▼
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
htmx_trigger_name
0
str | None
▼
def htmx_trigger_name(self) -> str | None
Returns
str | None
htmx_current_url
0
str | None
▼
The browser's current URL from HX-Current-URL header.
property
htmx_current_url
0
str | None
▼
def htmx_current_url(self) -> str | None
Returns
str | None
htmx_current_url_abs_path
0
str | None
▼
The path portion of the browser's current URL.
property
htmx_current_url_abs_path
0
str | None
▼
def htmx_current_url_abs_path(self) -> str | None
Returns
str | None
htmx_partial
0
str | None
▼
The partial element name from HX-Partial header (htmx 4.0+).
property
htmx_partial
0
str | None
▼
def htmx_partial(self) -> str | None
Returns
str | None
content_type
0
str | None
▼
The Content-Type header value.
property
content_type
0
str | None
▼
def content_type(self) -> str | None
Returns
str | None
content_length
0
int | None
▼
The Content-Length header as int.
property
content_length
0
int | None
▼
def content_length(self) -> int | None
Returns
int | None
url
0
str
▼
Full request URL (path + query string).
property
url
0
str
▼
def url(self) -> str
Returns
str
with_url_scope
1
Request
▼
Return a copy of this request with a public URL scope attached.
with_url_scope
1
Request
▼
def with_url_scope(self, scope: RequestUrlScope | str | None) -> Request
Parameters
| Name | Type | Description |
|---|---|---|
scope |
— |
Returns
Request
scoped_url
1
str
▼
Apply the request URL scope to an app-root path.
scoped_url
1
str
▼
def scoped_url(self, path: str) -> str
Parameters
| Name | Type | Description |
|---|---|---|
path |
— |
Returns
str
url_for
2
str
▼
Reverse a named route and apply this request's URL scope.
url_for
2
str
▼
def url_for(self, name: str, /, **params: Any) -> str
Parameters
| Name | Type | Description |
|---|---|---|
name |
— |
|
**params |
— |
Returns
str
body
0
bytes
▼
Read the full request body.
Result is cached — the ASGI receive is consumed on…
async
body
0
bytes
▼
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
stream
0
AsyncGenerator[bytes]
▼
async def stream(self) -> AsyncGenerator[bytes]
Returns
AsyncGenerator[bytes]
json
0
Any
▼
Parse the body as JSON.
async
json
0
Any
▼
async def json(self) -> Any
Returns
Any
text
0
str
▼
Read the body as text (UTF-8).
async
text
0
str
▼
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
form
0
FormData
▼
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
4
Request
▼
Create a Request from an ASGI scope and receive callable.
Reuses request_id fr…
classmethod
from_asgi
4
Request
▼
def from_asgi(cls, scope: Scope, receive: Receive, path_params: dict[str, str] | None = None, *, url_for: Callable[..., str] | None = None) -> Request
Create a Request from an ASGI scope and receive callable.
Reuses request_id from scope["extensions"]["request_id"] when Pounce (or another ASGI server) has already set it, avoiding redundant UUID generation.
Parameters
| Name | Type | Description |
|---|---|---|
scope |
— |
|
receive |
— |
|
path_params |
— |
Default:None
|
url_for |
— |
Default:None
|
Returns
Request