{"id":4220,"library":"python-fasthtml","title":"FastHTML","description":"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.","status":"active","version":"0.13.3","language":"en","source_language":"en","source_url":"https://github.com/AnswerDotAI/fasthtml","tags":["web-framework","html","asgi","starlette","htmx","frontend"],"install":[{"cmd":"pip install fasthtml uvicorn","lang":"bash","label":"Install FastHTML and Uvicorn"}],"dependencies":[{"reason":"ASGI server required to run FastHTML applications.","package":"uvicorn","optional":false},{"reason":"FastHTML is built on Starlette and inherits its ASGI capabilities. Usually handled as a transitive dependency.","package":"starlette","optional":false}],"imports":[{"symbol":"FastHTML","correct":"from fasthtml import FastHTML"},{"symbol":"HTML","correct":"from fasthtml.common import HTML"},{"symbol":"H1","correct":"from fasthtml.common import H1"},{"symbol":"P","correct":"from fasthtml.common import P"},{"symbol":"A","correct":"from fasthtml.common import A"},{"symbol":"Capture","correct":"from fasthtml.components import Capture"}],"quickstart":{"code":"from fasthtml.common import *\nfrom uvicorn import run\n\napp = FastHTML()\n\n# Global counter for demonstration\ncounter_val = 0\n\n@app.get('/')\ndef home():\n    return (\n        Title('FastHTML Counter with HTMX'),\n        H1('Click Counter'),\n        P(\n            'Count: ',\n            A(\n                counter_val, \n                id='count', \n                _hx_get='/count', \n                _hx_swap='outerHTML', \n                _hx_trigger='click'\n            )\n        )\n    )\n\n@app.get('/count')\ndef count_update():\n    global counter_val\n    counter_val += 1\n    return A(\n        counter_val, \n        id='count', \n        _hx_get='/count', \n        _hx_swap='outerHTML', \n        _hx_trigger='click'\n    )\n\nif __name__ == '__main__':\n    # Run with uvicorn: uvicorn main:app --reload\n    run(app, port=8000)\n","lang":"python","description":"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."},"warnings":[{"fix":"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.","message":"FastHTML implicitly renders HTML components returned from route functions. If you need to return a custom Starlette/FastAPI `Response` object (e.g., `RedirectResponse`, `JSONResponse`), ensure it's explicitly imported and returned, as FastHTML's auto-rendering will be bypassed.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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()`.","message":"Handling complex form data, especially file uploads or multipart forms, might require using the `Capture` component. While simple form parameters are automatically injected into route function arguments, accessing raw request bodies or specific file metadata is less direct.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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`).","message":"FastHTML is actively developed and currently below version 1.0. Minor version updates may introduce breaking changes to the API, internal structures, or default behaviors without a major version increment. Always review release notes carefully when upgrading.","severity":"breaking","affected_versions":"< 1.0.0"},{"fix":"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.","message":"Integrating custom Starlette middleware or lifespan events (`on_startup`, `on_shutdown`) requires understanding FastHTML's wrappers. Direct use of `app.add_middleware` might be less idiomatic than expected, and lifespan events are managed via a dedicated `Lifespan` class.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}