DEV Community

Alex Spinov
Alex Spinov

Posted on

FastHTML Has a Free API You Should Know About

FastHTML is a Python framework that lets you build modern web applications using pure Python — no JavaScript, no templates, no build step. HTML is generated from Python functions.

Why FastHTML Changes Python Web Dev

A Python developer wanted to build a web app but didn't want to learn React, set up webpack, or write JavaScript. FastHTML lets them build interactive web apps in pure Python — with htmx for interactivity.

Key Features:

  • Pure Python — No JavaScript, no templates
  • htmx Integrated — Interactive without writing JS
  • FastAPI-Based — Familiar routing and dependency injection
  • Component System — Reusable Python components
  • Hot Reload — Instant updates during development

Quick Start

pip install python-fasthtml
Enter fullscreen mode Exit fullscreen mode
from fasthtml.common import *

app, rt = fast_app()

@rt("/")
def get():
    return Titled("My App",
        P("Welcome to FastHTML!"),
        Button("Click me", hx_get="/clicked", hx_target="#result"),
        Div(id="result")
    )

@rt("/clicked")
def get():
    return P("Button was clicked!")

serve()
Enter fullscreen mode Exit fullscreen mode

Todo App in 20 Lines

app, rt, todos, Todo = fast_app("todos.db", id=int, title=str, done=bool)

@rt("/")
def get():
    items = [Li(t.title, " ", A("delete", hx_delete=f"/todo/{t.id}")) for t in todos()]
    return Titled("Todos", Ul(*items), Form(Input(name="title"), Button("Add"), hx_post="/todo"))

@rt("/todo")
def post(todo: Todo): return todos.insert(todo)

@rt("/todo/{id}")
def delete(id: int): todos.delete(id)

serve()
Enter fullscreen mode Exit fullscreen mode

Why Choose FastHTML

  1. Python only — no JavaScript needed
  2. Interactive — htmx provides interactivity
  3. Simple — full app in one file

Check out FastHTML docs to get started.


Need web solutions? Check out my Apify actors or email spinov001@gmail.com for custom solutions.

Top comments (0)