FastHTML is a lightweight and performant Python library designed for building dynamic HTML web applications with minimal code. It leverages ASGI for high performance and integrates well with technologies like HTMX for interactive user experiences. As of version 0.13.3, it is under active development with frequent minor releases.
pip install fasthtml uvicornVerified import paths — ran on the pinned version, not inferred.
This quickstart creates a simple FastHTML application that displays a clickable counter. It leverages HTMX to update the counter value on the page without a full page reload, demonstrating FastHTML's strength in building interactive UIs.
For explicit response types, import and return `from starlette.responses import JSONResponse` or `RedirectResponse` directly. For HTML, ensure your route returns FastHTML's `HTML` components or a string.
For multipart forms and file uploads, use `from fasthtml.components import Capture` and pass `request: Capture` as an argument to your route function to access `request.form()` or `request.files()`.
Consult the GitHub release notes (`https://github.com/AnswerDotAI/fasthtml/releases`) for each upgrade. Pin specific minor versions in your `requirements.txt` to control upgrades (e.g., `fasthtml~=0.13.0`).
For middleware, use `from starlette.middleware import Middleware` and pass them to the `FastHTML` constructor. For lifespan, refer to FastHTML's documentation on its `Lifespan` class and `on_event` decorator introduced in recent versions.