htmx#

class litestar.plugins.htmx.HTMXPlugin#

Bases: InitPluginProtocol

HTMX Plugin.

__init__(config: HTMXConfig | None = None) None#

Initialize the plugin.

Parameters:

config – Configuration for flash messages, including the template engine instance.

on_app_init(app_config: AppConfig) AppConfig#

Register the HTMX configuration.

Parameters:

app_config – The application configuration.

Returns:

The application configuration with the message callable registered.

class litestar.plugins.htmx.HTMXConfig#

Bases: object

Configuration for HTMX Plugin.

set_request_class_globally: bool = True#

Sets the app_config.request_class to the HTMXRequest class at the application level. Defaults to True

__init__(set_request_class_globally: bool = True) None#
class litestar.plugins.htmx.HTMXDetails#

Bases: object

HTMXDetails holds all the values sent by HTMX client in headers and provide convenient properties.

__init__(request: Request) None#

Initialize HTMXDetails

__bool__() bool#

Check if request is sent by an HTMX client.

property boosted: bool#

Check if request is boosted.

property current_url: str | None#

Current url value sent by HTMX client.

property current_url_abs_path: str | None#

Current url abs path value, to get query and path parameter sent by HTMX client.

property history_restore_request: bool#

If True then, request is for history restoration after a miss in the local history cache.

property prompt: str | None#

User Response to prompt.

<button hx-delete="/account" hx-prompt="Enter your account name to confirm deletion">Delete My Account</button>
property target: str | None#

ID of the target element if provided on the element.

property trigger: str | None#

ID of the triggered element if provided on the element.

property trigger_name: str | None#

Name of the triggered element if provided on the element.

property triggering_event: Any#

Name of the triggered event.

This value is added by event-header extension of HTMX to the Triggering-Event header to requests.

class litestar.plugins.htmx.HTMXHeaders#

Bases: str, Enum

Enum for HTMX Headers

__new__(value)#
class litestar.plugins.htmx.HTMXRequest#

Bases: Request

HTMX Request class to work with HTMX client.

__init__(scope: Scope, receive: Receive = <function empty_receive>, send: Send = <function empty_send>) None#

Initialize HTMXRequest

class litestar.plugins.htmx.HXStopPolling#

Bases: Response

Stop HTMX client from Polling.

__init__() None#

Initialize

class litestar.plugins.htmx.HXLocation#

Bases: Response

Client side redirect without full page reload.

__init__(redirect_to: str, source: str | None = None, event: str | None = None, target: str | None = None, swap: Literal['innerHTML', 'outerHTML', 'beforebegin', 'afterbegin', 'beforeend', 'afterend', 'delete', 'none', None] | None = None, hx_headers: dict[str, Any] | None = None, values: dict[str, str] | None = None, **kwargs: Any) None#

Initialize HXLocation, Set status code to 200 (required by HTMX), and pass redirect url.

class litestar.plugins.htmx.ClientRedirect#

Bases: Response

HTMX Response class to support client side redirect.

__init__(redirect_to: str) None#

Set status code to 200 (required by HTMX), and pass redirect url.

class litestar.plugins.htmx.ClientRefresh#

Bases: Response

Response to support HTMX client page refresh

__init__() None#

Set Status code to 200 and set headers.

class litestar.plugins.htmx.PushUrl#

Bases: Generic[T], Response[T]

Response to push new url into the history stack.

__init__(content: T, push_url: str | bool, **kwargs: Any) None#

Initialize PushUrl.

class litestar.plugins.htmx.ReplaceUrl#

Bases: Generic[T], Response[T]

Response to replace url in the Browser Location bar.

__init__(content: T, replace_url: str | bool, **kwargs: Any) None#

Initialize ReplaceUrl.

class litestar.plugins.htmx.Reswap#

Bases: Generic[T], Response[T]

Response to specify how the response will be swapped.

__init__(content: T, method: Literal['innerHTML', 'outerHTML', 'beforebegin', 'afterbegin', 'beforeend', 'afterend', 'delete', 'none', None], **kwargs: Any) None#

Initialize Reswap.

class litestar.plugins.htmx.Retarget#

Bases: Generic[T], Response[T]

Response to target different element on the page.

__init__(content: T, target: str, **kwargs: Any) None#

Initialize Retarget.

class litestar.plugins.htmx.TriggerEvent#

Bases: Generic[T], Response[T]

Trigger Client side event.

__init__(content: T, name: str, after: Literal['receive', 'settle', 'swap', None], params: dict[str, Any] | None = None, **kwargs: Any) None#

Initialize TriggerEvent.

class litestar.plugins.htmx.HTMXTemplate#

Bases: Template

HTMX template wrapper

__init__(push_url: str | bool | None = None, re_swap: Literal['innerHTML', 'outerHTML', 'beforebegin', 'afterbegin', 'beforeend', 'afterend', 'delete', 'none', None] | None = None, re_target: str | None = None, trigger_event: str | None = None, params: dict[str, Any] | None = None, after: Literal['receive', 'settle', 'swap', None] | None = None, **kwargs: Any) None#

Create HTMXTemplate response.

Parameters:
  • push_url – Either a string value specifying a URL to push to browser history or False to prevent HTMX client from pushing a url to browser history.

  • re_swap – Method value to instruct HTMX which swapping method to use.

  • re_target – Value for ‘id of target element’ to apply changes to.

  • trigger_event – Event name to trigger.

  • params – Dictionary of parameters if any required with trigger event parameter.

  • after – Changes to apply after receive, settle or swap event.

  • **kwargs – Additional arguments to pass to Template.

class litestar.plugins.htmx.HtmxHeaderType#

Bases: TypedDict

Type for hx_headers parameter in get_headers().

class litestar.plugins.htmx.LocationType#

Bases: TypedDict

Type for HX-Location header.

class litestar.plugins.htmx.TriggerEventType#

Bases: TypedDict

Type for HX-Trigger header.