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.
Instalación con revisión previa
Este activo requiere revisión. El prompt copiado pide dry-run, muestra escrituras y continúa solo tras confirmación.
npx -y tokrepo@latest install 143825f7-ee67-49a1-a994-6908bb1df20f --target codexPrimero dry-run, confirma las escrituras y luego ejecuta este comando.
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
Preguntas frecuentes
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.
Referencias (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
Relacionados en TokRepo
Fuente y agradecimientos
Created by Jeremy Howard / Answer.AI. Licensed under Apache 2.0.
AnswerDotAI/fasthtml — 8k+ stars
Discusión
Activos relacionados
BeeWare Toga — Native Cross-Platform GUI Apps in Python
Write native desktop and mobile applications in pure Python that render with platform-native widgets on macOS, Windows, Linux, iOS, Android, and the web.
Wails — Build Desktop Apps with Go and Web Technologies
Wails lets you create beautiful desktop applications using Go for the backend and any web frontend. Uses the OS native WebView (like Tauri) producing ~8MB binaries. No Electron bloat, full Go power, and access to native APIs via bindings.
Dioxus — Full-Stack App Framework for Web, Desktop, and Mobile
Dioxus is a full-stack app framework for Rust with a React-like API. Build web (WASM), desktop (native WebView), mobile (iOS/Android), TUI, and server-rendered apps from one codebase. Hooks, components, server functions, and hot reloading.
Sanic — Async Python Web Framework Built for Speed
Sanic is an async Python web framework built for speed. Native async/await from the ground up, HTTP/1.1 and HTTP/2, WebSocket, streaming, and auto-generated API docs. Designed to be fast, flexible, and easy to use.