Skip to main content

FastHTML

Welcome to the official FastHTML documentation.

FastHTML is a new next-generation web framework for fast, scalable web applications with minimal, compact code. It’s designed to be:

  • Powerful and expressive enough to build the most advanced, interactive web apps you can imagine.
  • Fast and lightweight, so you can write less code and get more done.
  • Easy to learn and use, with a simple, intuitive syntax that makes it easy to build complex apps quickly.

FastHTML apps are just Python code, so you can use FastHTML with the full power of the Python language and ecosystem. FastHTML’s functionality maps 1:1 directly to HTML and HTTP, but allows them to be encapsulated using good software engineering practices—so you’ll need to understand these foundations to use this library fully. To understand how and why this works, please read this first: fastht.ml/about.

Installation

Since fasthtml is a Python library, you can install it with:

pip install python-fasthtml

In the near future, we hope to add component libraries that can likewise be installed via pip.

Usage

For a minimal app, create a file “main.py” as follows:

main.py

from fasthtml.common import *

app,rt = fast_app()

@rt('/')
def get(): return Div(P('Hello World!'), hx_get="/change")

serve()

Running the app with python main.py prints out a link to your running app: http://localhost:5001. Visit that link in your browser and you should see a page with the text “Hello World!”. Congratulations, you’ve just created your first FastHTML app!

Adding interactivity is surprisingly easy, thanks to HTMX. Modify the file to add this function:

main.py

@rt('/change')
def get(): return P('Nice to be here!')

You now have a page with a clickable element that changes the text when clicked. When clicking on this link, the server will respond with an “HTML partial”—that is, just a snippet of HTML which will be inserted into the existing page. In this case, the returned element will replace the original P element (since that’s the default behavior of HTMX) with the new version returned by the second route.

This “hypermedia-based” approach to web development is a powerful way to build web applications.

Getting help from AI

Because FastHTML is newer than most LLMs, AI systems like Cursor, ChatGPT, Claude, and Copilot won’t give useful answers about it. To fix that problem, we’ve provided an LLM-friendly guide that teaches them how to use FastHTML. To use it, add this link for your AI helper to use:

This example is in a format based on recommendations from Anthropic for use with Claude Projects. This works so well that we’ve actually found that Claude can provide even better information than our own documentation! For instance, read through this annotated Claude chat for some great getting-started information, entirely generated from a project using the above text file as context.

If you use Cursor, type @doc then choose “Add new doc”, and use the /llms-ctx.txt link above. The context file is auto-generated from our llms.txt (our proposed standard for providing AI-friendly information)—you can generate alternative versions suitable for other models as needed.

Next Steps

Start with the official sources to learn more about FastHTML:

  • About: Learn about the core ideas behind FastHTML
  • Documentation: Learn from examples how to write FastHTML code
  • Idiomatic app: Heavily commented source code walking through a complete application, including custom authentication, JS library connections, and database use.

We also have a 1-hour intro video:

https://www.youtube.com/embed/Auqrm7WFc0I

The capabilities of FastHTML are vast and growing, and not all the features and patterns have been documented yet. Be prepared to invest time into studying and modifying source code, such as the main FastHTML repo’s notebooks and the official FastHTML examples repo:

Then explore the small but growing third-party ecosystem of FastHTML tutorials, notebooks, libraries, and components:

Finally, join the FastHTML community to ask questions, share your work, and learn from others:

Other languages and related projects

If you’re not a Python user, or are keen to try out a new language, we’ll list here other projects that have a similar approach to FastHTML. (Please reach out if you know of any other projects that you’d like to see added.)

  • htmgo (Go): “htmgo is a lightweight pure go way to build interactive websites / web applications using go & htmx. By combining the speed & simplicity of go + hypermedia attributes (htmx) to add interactivity to websites, all conveniently wrapped in pure go, you can build simple, fast, interactive websites without touching javascript. All compiled to a single deployable binary

If you’re just interested in functional HTML components, rather than a full HTMX server solution, consider:

  • fastcore.xml.FT: This is actually what FastHTML uses behind the scenes
  • htpy: Similar to fastcore.xml.FT, but with a somewhat different syntax
  • elm-html: Elm’s built-in HTML library with a type-safe functional approach
  • hiccup: Popular library for representing HTML in Clojure using vectors
  • hiccl: HTML generation library for Common Lisp inspired by Clojure’s Hiccup
  • Falco.Markup: F# HTML DSL and web framework with type-safe HTML generation
  • Lucid: Type-safe HTML generation for Haskell using monad transformers
  • dream-html: Part of the Dream web framework for OCaml, provides type-safe HTML templating

For other hypermedia application platforms, not based on HTMX, take a look at:

  • Hotwire/Turbo: Rails-oriented framework that similarly uses HTML-over-the-wire
  • LiveView: Phoenix framework’s solution for building interactive web apps with minimal JavaScript
  • Unpoly: Another HTML-over-the-wire framework with progressive enhancement
  • Livewire: Laravel’s take on building dynamic interfaces with minimal JavaScript

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_fasthtml-0.14.10.tar.gz (76.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_fasthtml-0.14.10-py3-none-any.whl (80.4 kB view details)

Uploaded Python 3

File details

Details for the file python_fasthtml-0.14.10.tar.gz.

File metadata

  • Download URL: python_fasthtml-0.14.10.tar.gz
  • Upload date:
  • Size: 76.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.2

File hashes

Hashes for python_fasthtml-0.14.10.tar.gz
Algorithm Hash digest
SHA256 18708a08922afd916c84e057d763834b591fdf56fcc823ae6f405288dddbd193
MD5 7541657886400250a46835d5f2c9fd38
BLAKE2b-256 1e05562913eb1466385aa498e36dcbe9d7d885053d2f6fa5a6f69d401d352554

See more details on using hashes here.

File details

Details for the file python_fasthtml-0.14.10-py3-none-any.whl.

File metadata

File hashes

Hashes for python_fasthtml-0.14.10-py3-none-any.whl
Algorithm Hash digest
SHA256 7235f81a0a43c1022d2a1ba4a200d696a3d7d398da83f388c4afeece70456acd
MD5 4c8a5caca58f90f9c6cb2d0b9aea379c
BLAKE2b-256 e1beced72c5ee71192d1ba42571f89a8100d5fb1a5f2ee28ceb4396773b4fbcc

See more details on using hashes here.

Release history Release notifications | RSS feed

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page