HTMX Support¶
Helpers for building HTMX-powered web applications with partial page updates.
HtmxHeaders¶
HtmxHeaders
dataclass
¶
Parsed HTMX request headers.
Injected into handlers that declare an HtmxHeaders parameter.
Provides typed access to all standard HTMX request headers.
Attributes:
| Name | Type | Description |
|---|---|---|
is_htmx |
bool
|
True if the request was made by HTMX (HX-Request header present). |
boosted |
bool
|
True if the request came from an hx-boost element. |
target |
str | None
|
The id of the target element (HX-Target header). |
trigger |
str | None
|
The id of the element that triggered the request (HX-Trigger header). |
trigger_name |
str | None
|
The name of the trigger element (HX-Trigger-Name header). |
current_url |
str | None
|
The current browser URL (HX-Current-URL header). |
prompt |
str | None
|
The user response to an hx-prompt (HX-Prompt header). |
Source code in src/agenticapi/interface/htmx.py
from_scope
classmethod
¶
Extract HTMX headers from an ASGI scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
dict[str, Any]
|
The ASGI scope dict containing request headers. |
required |
Returns:
| Type | Description |
|---|---|
HtmxHeaders
|
Parsed HtmxHeaders instance. |
Source code in src/agenticapi/interface/htmx.py
htmx_response_headers¶
htmx_response_headers ¶
htmx_response_headers(
*,
trigger: str | None = None,
trigger_after_settle: str | None = None,
trigger_after_swap: str | None = None,
redirect: str | None = None,
refresh: bool = False,
retarget: str | None = None,
reswap: str | None = None,
push_url: str | bool | None = None,
replace_url: str | bool | None = None,
) -> dict[str, str]
Build HTMX response headers.
Use with any response type to control HTMX client-side behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trigger
|
str | None
|
Trigger client-side events after response is received. |
None
|
trigger_after_settle
|
str | None
|
Trigger events after the settling step. |
None
|
trigger_after_swap
|
str | None
|
Trigger events after the swap step. |
None
|
redirect
|
str | None
|
Redirect the browser to a new URL. |
None
|
refresh
|
bool
|
If True, trigger a full page refresh. |
False
|
retarget
|
str | None
|
Override the swap target CSS selector. |
None
|
reswap
|
str | None
|
Override the swap strategy (innerHTML, outerHTML, etc.). |
None
|
push_url
|
str | bool | None
|
Push a URL into the browser history. |
None
|
replace_url
|
str | bool | None
|
Replace the current URL in the browser. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dict of HTMX response headers. |
Example
headers = htmx_response_headers(trigger="itemAdded", reswap="outerHTML") return HTMLResult(content="