Utility API
These helpers support static asset inspection, SVG rendering, form-validation mapping, and DataTable URL construction. They are useful when building wrappers or integrating Faststrap with an existing application layer.
DataTable Query Helpers
from faststrap import datatable_page_url, datatable_query_params
params = datatable_query_params(
sort="created_at",
direction="desc",
search="pending",
page=2,
per_page=25,
)
url = datatable_page_url("/orders", page=2, per_page=25, sort="created_at", direction="desc")
The helpers preserve repeated filter values and keep URL construction in one place. Use datatable_export_params() when an export endpoint should receive the current sort, search, and filter state without pagination.
Form Error Helpers
from faststrap import extract_field_error, map_formgroup_validation
message = extract_field_error(errors, "email")
state = map_formgroup_validation(errors, "email")
These helpers accept mapping-shaped validation errors and return values suitable for FormGroup, Input, and related form components.
API Reference
faststrap.components.display.data_table.datatable_export_params(*, sort=None, direction='asc', search=None, search_param='q', filters=None, include_pagination=False, page=None, per_page=None)
Build query params for exporting DataTable state.
This helper mirrors the DataTable query contract and is intended to be passed into ExportButton(extra_params=...).
Source code in src/faststrap/components/display/data_table.py
faststrap.components.display.data_table.datatable_query_params(*, sort=None, direction='asc', search=None, search_param='q', filters=None, page=None, per_page=None)
Build the common DataTable query contract for links and handlers.
Source code in src/faststrap/components/display/data_table.py
faststrap.components.display.data_table.datatable_page_url(base_url, *, page, per_page=None, sort=None, direction='asc', search=None, search_param='q', filters=None)
Build a URL for one DataTable page while preserving current state.
Source code in src/faststrap/components/display/data_table.py
faststrap.components.forms.errors.extract_field_error(errors, field)
Extract a single displayable error message for a field.
Source code in src/faststrap/components/forms/errors.py
faststrap.components.forms.errors.map_formgroup_validation(errors, field)
Return FormGroup-ready validation flags for a given field.
Source code in src/faststrap/components/forms/errors.py
faststrap.utils.static_management.get_faststrap_static_url(app)
Get the URL where FastStrap static files are mounted for this specific app.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
Any
|
The FastHTML app instance |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The static URL if mounted, None otherwise |
Source code in src/faststrap/utils/static_management.py
faststrap.utils.static_management.cleanup_static_resources()
Clean up extracted static resources.
Source code in src/faststrap/utils/static_management.py
faststrap.components.display.svg.render_svg(svg, *, sanitize=True, allowed_tags=None, allowed_attributes=None, allowed_protocols=None)
Render SVG markup with optional sanitization.