Cette page est affichée en anglais. Une traduction française est en cours.
SkillsApr 7, 2026·2 min de lecture

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.

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

# 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

@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

app, rt = fast_app(
    before=Beforeware(lambda req, sess: redirect("/login") if not sess.get("user") else None)
)

4. Database Integration

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

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 et remerciements

Created by Jeremy Howard / Answer.AI. Licensed under Apache 2.0.

AnswerDotAI/fasthtml — 8k+ stars

Discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.