# 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
## Quick Start
```bash
pip install python-fasthtml
```
Build interactive AI web apps in 10 lines of Python.
## What is FastHTML?
FastHTML is a Python web framework for building modern web applications in pure Python — no JavaScript, no templates, no frontend build tools.
**In one sentence**: Pure-Python web framework using HTMX for interactivity — Python functions generate HTML. The fastest way to build AI dashboards and agent UIs.
**For**: AI developers who don't want to learn frontend frameworks.
## Core Features
### 1. Pure-Python Components
Build HTML elements with Python functions.
### 2. HTMX Interactivity
No JavaScript — HTMX handles partial updates and form submissions.
### 3. Built-In Auth and Database
SQLite database and authentication middleware out of the box.
### 4. AI App Templates
Quickly build chat interfaces, dashboards, and other AI apps.
## FAQ
**Q: Production ready?**
A: Yes — built on Starlette and Uvicorn, used by fast.ai in production.
**Q: Who created it?**
A: Jeremy Howard, founder of fast.ai.
## Source & Thanks
> [AnswerDotAI/fasthtml](https://github.com/AnswerDotAI/fasthtml) — 8k+ stars, Apache 2.0
---
Source: https://tokrepo.com/en/workflows/fasthtml-build-ai-web-apps-pure-python-143825f7
Author: Skill Factory