Repo of the Day
answerdotai/fasthtml
Published: Dec 11, 2024
Open repository ↗The fastest way to create an HTML app. Uses python and looks pretty cool.
Summary
FastHTML is a Python web framework for building web applications where the application code, routing, and HTML markup are written directly in Python. It uses HTMX to add interactivity by returning small HTML snippets from the server, so pages can update without a separate JavaScript front end. The library is published as the python-fasthtml package and is distributed under the Apache-2.0 license.
What it is useful for
FastHTML is aimed at engineers who want to build interactive web apps while staying inside the Python ecosystem. The README frames it as mapping 1:1 to HTML and HTTP, which the project says makes it easier to apply ordinary software engineering practices to web code. The documented examples cover two ends of a spectrum: a "Hello World!" page whose text changes when clicked, and a more complete "idiomatic app" in the examples directory that walks through custom authentication, JavaScript library connections, and database use. The project also explicitly targets engineers using AI coding assistants, and ships an llms-ctx.txt file because FastHTML is newer than most LLM training data, so off-the-shelf tools like Cursor, ChatGPT, Claude, and Copilot would otherwise give poor answers.
How engineers can use it
The documented setup is to install with pip install python-fasthtml, create a main.py file, and run it with python main.py, which serves the app on http://localhost:5001. The minimal example from the README is:
from fasthtml.common import *
app,rt = fast_app()
@rt('/')
def get(): return Div(P('Hello World!'), hx_get="/change")
serve()
Adding a second route at /change that returns a different paragraph shows the core pattern: a request returns an HTML partial, and HTMX replaces the existing element with the new one. The README warns that "not all the features and patterns have been documented yet," so engineers are directed to read the source notebooks, the example repository, and the annotated adv_app.py to learn idiomatic usage. Further reference material listed in the README includes the official docs, an About page explaining the design, a one-hour intro video, and a Discord for community questions.