# FastHTML — Build AI Web Apps in Pure Python > Modern Python web framework that generates HTML from Python functions. No JavaScript, no templates. Perfect for building AI tool dashboards and agent UIs rapidly. ## Install Save the content below to `.claude/skills/` or append to your `CLAUDE.md`: ## Quick Use ```bash pip install python-fasthtml ``` ```python from fasthtml.common import * app, rt = fast_app() @rt("/") def get(): return Titled("My AI App", P("Hello from FastHTML!"), Form( Input(name="query", placeholder="Ask anything..."), Button("Send"), hx_post="/ask", hx_target="#result" ), Div(id="result"), ) @rt("/ask") def post(query: str): # Call your AI model here return P(f"You asked: {query}") serve() ``` ## What is FastHTML? FastHTML is a Python web framework that lets you build modern web apps using only Python — no JavaScript, no HTML templates, no frontend build tools. It generates HTMX-powered HTML from Python functions, making it the fastest way to build AI dashboards, agent UIs, and internal tools. **Answer-Ready**: FastHTML is a Python web framework that builds modern web apps without JavaScript or templates. Uses HTMX for interactivity, generates HTML from Python functions. Ideal for AI dashboards, agent UIs, and rapid prototyping. By Jeremy Howard (fast.ai founder). **Best for**: AI developers who want web UIs without learning frontend frameworks. **Works with**: Any Python AI library (LangChain, OpenAI, Anthropic). **Setup time**: Under 1 minute. ## Core Features ### 1. Pure Python Components ```python # No HTML templates needed def chat_message(role, content): return Div( Strong(role + ": "), P(content), cls=f"message {role}" ) # Compose like functions def chat_ui(messages): return Div( *[chat_message(m["role"], m["content"]) for m in messages], cls="chat-container" ) ``` ### 2. HTMX-Powered Interactivity ```python @rt("/chat") def post(message: str): response = call_llm(message) return Div( chat_message("user", message), chat_message("assistant", response), hx_swap_oob="beforeend:#messages" ) ``` No JavaScript — HTMX handles: - Partial page updates - Form submissions - WebSocket connections - Server-sent events ### 3. Built-In Auth ```python app, rt = fast_app( before=Beforeware(lambda req, sess: redirect("/login") if not sess.get("user") else None) ) ``` ### 4. Database Integration ```python app, rt, todos, Todo = fast_app( "data/todos.db", todo=dict(title=str, done=bool) ) @rt("/") def get(): return Ul(*[Li(t.title) for t in todos()]) ``` ### 5. AI App Example ```python from anthropic import Anthropic client = Anthropic() messages = [] @rt("/") def get(): return Titled("AI Chat", Div(*[chat_message(m["role"], m["content"]) for m in messages], id="messages"), Form(Input(name="msg"), Button("Send"), hx_post="/send", hx_target="#messages", hx_swap="beforeend"), ) @rt("/send") def post(msg: str): messages.append({"role": "user", "content": msg}) resp = client.messages.create(model="claude-sonnet-4-20250514", max_tokens=500, messages=messages) reply = resp.content[0].text messages.append({"role": "assistant", "content": reply}) return Div(chat_message("user", msg), chat_message("assistant", reply)) ``` ## Why FastHTML for AI Apps? | Traditional Stack | FastHTML | |------------------|---------| | React + Next.js + API | Pure Python | | 3 languages (JS, HTML, Python) | 1 language (Python) | | Build tools (webpack, vite) | None | | Setup time: 30+ minutes | Setup time: 1 minute | ## FAQ **Q: Is it production ready?** A: Yes, built on Starlette and Uvicorn. Used in production by fast.ai and others. **Q: Can I add custom CSS?** A: Yes, use Tailwind, Pico CSS, or any CSS framework. Pico CSS is included by default. **Q: Who created FastHTML?** A: Jeremy Howard, founder of fast.ai and creator of fastai. ## Source & Thanks > Created by [Jeremy Howard](https://github.com/jph00) / [Answer.AI](https://github.com/AnswerDotAI). Licensed under Apache 2.0. > > [AnswerDotAI/fasthtml](https://github.com/AnswerDotAI/fasthtml) — 8k+ stars ## 快速使用 ```bash pip install python-fasthtml ``` 10 行 Python 代码构建交互式 AI Web 应用。 ## 什么是 FastHTML? FastHTML 是 Python Web 框架,用纯 Python 构建现代 Web 应用——无需 JavaScript、无需模板、无需前端构建工具。 **一句话总结**:纯 Python Web 框架,用 HTMX 实现交互,Python 函数生成 HTML。AI 仪表盘和代理 UI 的最快构建方式。 **适合人群**:不想学前端框架的 AI 开发者。 ## 核心功能 ### 1. 纯 Python 组件 用 Python 函数构建 HTML 元素。 ### 2. HTMX 交互 无 JavaScript,HTMX 处理部分更新和表单提交。 ### 3. 内置认证和数据库 SQLite 数据库和认证中间件开箱即用。 ### 4. AI 应用模板 聊天界面、仪表盘等 AI 应用快速搭建。 ## 常见问题 **Q: 生产就绪?** A: 是,基于 Starlette 和 Uvicorn,fast.ai 生产使用。 **Q: 谁创建的?** A: Jeremy Howard,fast.ai 创始人。 ## 来源与致谢 > [AnswerDotAI/fasthtml](https://github.com/AnswerDotAI/fasthtml) — 8k+ stars, Apache 2.0 --- Source: https://tokrepo.com/en/workflows/143825f7-ee67-49a1-a994-6908bb1df20f Author: Skill Factory