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 it is
FastHTML is a Python web framework that lets you build modern, interactive web applications entirely in Python. It uses HTMX for client-side interactivity, so you write Python functions that return HTML components without touching JavaScript. Server-side rendering is the default, making it naturally suited for AI-integrated applications where the backend does the heavy lifting.
FastHTML targets Python developers, data scientists, and AI engineers who want to build web UIs for their models and tools without learning a frontend framework.
How it saves time or tokens
Traditional web development requires separate frontend and backend codebases, typically involving React or Vue plus a Python API. FastHTML eliminates the frontend build step entirely. You write Python functions decorated with routes, return HTML components, and HTMX handles dynamic updates. This cuts the technology stack in half and removes the need for API serialization between frontend and backend.
How to use
- Install FastHTML:
pip install python-fasthtml
- Create a minimal app:
from fasthtml.common import *
app, rt = fast_app()
@rt('/')
def get():
return Titled('Hello', P('Welcome to FastHTML'))
serve()
- Run your app:
python main.py
# Open http://localhost:5001
Example
An AI chat interface built with FastHTML:
from fasthtml.common import *
import openai
app, rt = fast_app()
messages = []
@rt('/')
def get():
chat_list = Ul(*[Li(m) for m in messages], id='chat')
form = Form(
Input(name='msg', placeholder='Ask anything...'),
Button('Send'),
hx_post='/chat', hx_target='#chat', hx_swap='innerHTML'
)
return Titled('AI Chat', chat_list, form)
@rt('/chat')
def post(msg: str):
messages.append(f'You: {msg}')
response = openai.chat.completions.create(
model='gpt-4o-mini',
messages=[{'role': 'user', 'content': msg}]
)
messages.append(f'AI: {response.choices[0].message.content}')
return Ul(*[Li(m) for m in messages])
serve()
Related on TokRepo
- Coding tools — developer tools for building AI applications
- AI tools for content — content generation and web tools
Common pitfalls
- FastHTML uses HTMX for interactivity; complex client-side state management (like drag-and-drop) still requires JavaScript
- The framework is relatively new; community resources and third-party plugins are limited compared to Flask or Django
- Server-side rendering means every interaction hits the server; for high-traffic applications, consider adding caching or rate limiting
Frequently Asked Questions
Streamlit is designed for data dashboards with a widget-based API. FastHTML is a general-purpose web framework that gives you full control over HTML structure, routing, and styling. FastHTML produces standard web apps; Streamlit produces data apps with a specific look and feel.
Yes. FastHTML works with any CSS framework. You can include Tailwind CSS, Bootstrap, or custom stylesheets. The framework generates standard HTML, so any CSS applies normally.
Yes. FastHTML supports WebSocket connections for real-time features like streaming LLM responses. You define WebSocket handlers alongside regular HTTP routes in the same Python file.
Yes. FastHTML apps run on any Python hosting platform. Deploy with Uvicorn behind Nginx for production. Railway, Render, and Fly.io all support Python ASGI applications, which FastHTML uses under the hood.
No. The core value proposition is building interactive web apps without JavaScript. HTMX handles dynamic content updates through HTML attributes. You may need minimal JavaScript only for highly custom client-side behaviors.
Citations (3)
- FastHTML GitHub— FastHTML builds web apps in pure Python with HTMX
- HTMX Docs— HTMX provides interactivity through HTML attributes
- FastHTML Docs— FastHTML documentation and tutorials
Related on TokRepo
Source & Thanks
Created by Jeremy Howard / Answer.AI. Licensed under Apache 2.0.
AnswerDotAI/fasthtml — 8k+ stars
Discussion
Related Assets
Claude-Flow — Multi-Agent Orchestration for Claude Code
Layers swarm and hive-mind multi-agent orchestration on top of Claude Code with 64 specialized agents, SQLite memory, and parallel execution.
ccusage — Real-Time Token Cost Tracker for Claude Code
CLI that reads ~/.claude logs and breaks down Claude Code token spend by day, session, and project — pluggable into your statusline.
SuperClaude — Workflow Framework for Claude Code
Adds 16+ slash commands, 9 cognitive personas, and a smart flag system to Claude Code in one pipx install.