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

Point your AI coding assistant at our llms.txt documentation index so it can read up-to-date FastHTML docs on demand:

In Python environments with pyskills, load fasthtml.skill and call doc(fasthtml.skill) for the same compact guide and doc links.

For Cursor, type @doc, choose “Add new doc”, and enter the llms.txt link above.

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:

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

Metadata

Release files for python-fasthtml 0.15.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-fasthtml 0.15.0
File Size Uploaded Provenance Actions
python_fasthtml-0.15.0.tar.gz 97.0 kB Without provenance Details for python_fasthtml-0.15.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-fasthtml 0.15.0
File Interpreter ABI Platform Actions
python_fasthtml-0.15.0-py3-none-any.whl Python 3 none any Details for python_fasthtml-0.15.0-py3-none-any.whl

Total release size: 196.6 kB

Release files / python_fasthtml-0.15.0.tar.gz

Download URL python_fasthtml-0.15.0.tar.gz
Size 97.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0e878e608b50b173c7210a9c0ce988cf6d166f63d918671f75457c55334f71bf
BLAKE2b-256 checksum
How to use checksums
209d7153a55669e6fc903cd159c66565d33c4714c3141c7fdcef59ce091aff6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / python_fasthtml-0.15.0-py3-none-any.whl

Download URL python_fasthtml-0.15.0-py3-none-any.whl
Size 99.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a520a5a04b538fe3b2b8cb81737679d0c61a9baa83546d4e1aa144ebd931113e
BLAKE2b-256 checksum
How to use checksums
a22e45b0a6c863a4d7ea4c701b88fd47a5b9d35d9bb040c98435cb894f378b76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Security for python-fasthtml 0.15.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.15.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page