https://fastht.ml/
FastHTML Read docs
Modern web applications in pure Python
Built on solid web foundations, not the latest fads - with FastHTML
you can get started on anything from simple dashboards to scalable
web applications in minutes.
Learn more Video poster Watch intro 7min 30sec
Youtube icon
Close
Try now
X
This home page is a FastHTML app.
Click the buttons below to see four small, live components in action.
card3d.py
Copy Copied!
def card_3d_demo():
"""This is a standalone isolated Python component.
Behavior and styling is scoped to the component."""
def card_3d(text, background, amt, left_align):
# JS and CSS can be defined inline or in a file
scr = ScriptX('card3d.js', amt=amt)
align='left' if left_align else 'right'
sty = StyleX('card3d.css', background=f'url({background})', align=align)
return Div(text, Div(), sty, scr)
# Design credit: https://codepen.io/markmiro/pen/wbqMPa
card = card_3d("Mouseover me", bgurl, amt=1.5, left_align=True)
return Div(card, style=cardcss)
Mouseover me
weather.py
Copy Copied!
async def weather_table():
"""Dynamically generated python content
directly incorporated into the HTML"""
# These are actual real-time weather.gov observations
results = await all_weather()
rows = [Tr(Td(city), *map(Td, d.values()), cls="even:bg-purple/5")
for city,d in results.items()]
flds = 'City', 'Temp (C)', 'Wind (kmh)', 'Humidity'
head = Thead(*map(Th, flds), cls="bg-purple/10")
return Table(head, *rows, cls="w-full")
City Temp (C) Wind (kmh) Humidity
New York 27.8 9.4 60.3
Los Angeles 18.6 2.0 74.4
Chicago 32.2 11.2 48.6
Houston 33.9 22.3 52.4
Washington 30 20.5 63.0
accordion.py
Copy Copied!
def accordion_demo():
"""UI components can be styled and reused.
UI libraries can be installed using `pip`."""
accs = [accordion(id=id, question=q, answer=a,
question_cls="text-black s-body", answer_cls=a_cls, container_cls=c_cls)
for id,(q,a) in enumerate(qas)]
return Div(*accs, cls=acc_cls)
[ ]
What is this?
Expand Collapse
This is a little demo of a reusable accordion component.
[ ]
What is FastHTML?
Expand Collapse
FastHTML is a Python library for building web apps.
[ ]
What is HTMX?
Expand Collapse
HTMX is a JavaScript library that extends browser interaction
behavior.
todos.py
Copy Copied!
class Todo:
"Use any database system you like"
id:int; title:str; done:bool
def __ft__(self):
"`__ft__` defines how FastHTML renders an object"
return Li(" " if self.done else "", self.title)
todos = db.create(Todo)
def todos_table():
"This example uses the `fastlite` DB lib"
return Ul(*todos(), cls=list_class)
DB-generated todo list
* Create sample todos
* Create a sample FastHTML app
* Read this todo list
* Components
* Dynamic
* Reusable
* Databases
GET STARTED IN MINUTES
The fastest way to create a real web application.
With FastHTML you create good-looking modern web applications in pure
Python and deploy them in minutes.
Get started fast
A single Python file is all that's needed to create any app you can
think of. Or bring in any Python or JS library you like.
Flexibility
FastHTML provides full access to HTTP, HTML, JS, and CSS, bringing
the foundations of the web to you. There's no limits to what you can
build.
Speed & scale
FastHTML applications are fast and scalable. They're also easy to
deploy, since you can use any hosting service that supports Python.
TECH STACK
FastHTML scales up and scales down.
Read more about our design philosophy here , or click a button below:
Build on solid foundations
FastHTML stands on the shoulders of giants:
ASGI
ASGI
HTMX
HTMX
HTTP
HTTP
HTML
HTML
Use tools you already know
FastHTML embraces the familiar:
Python
Python
Uvicorn
Uvicorn
Starlette
Starlette
SQLite
SQLite
Deploy anywhere
FastHTML runs anywhere Python does, including 1-click deploy to:
Railway
Railway
Vercel
Vercel
Hugging Face
Hugging Face
PythonAnywhere
PythonAnywhere
SAMPLES
See FastHTML in action
FastHTML can be used for everything from collaborative games to
multi-modal UI. We've selected small self-contained examples for you
to learn from.
Game of life
Arrow right icon
To-do
Arrow right icon
Chat bot
Arrow right icon
Pictionary AI
Arrow right icon
Discover all
FAQ
Questions? Answers.
Your top FastHTML questions clarified.
[ ]
What kinds of applications can be written with this?
Expand Collapse
It's good for: general purpose web applications (i.e anything you'd
build with React, Django, NexJS, etc); quick dashboards, prototypes,
and in-company apps (e.g. like what you might use gradio/streamlit/
etc for); Analytics/models/dashboards interactive reports; Custom
blogs and content-heavy sites where you also want some interactive/
dynamic content.
[ ]
Where can I deploy my FastHTML to? What's needed?
Expand Collapse
You can deploy a FastHTML app to any service or server that supports
Python. We have guides and helpers for Railway.app, Vercel, Hugging
Face Spaces, Replit, and PythonAnywhere. You can also use any VPS or
server, or any on-premise machine with Python installed. All major
operating systems are supported.
[ ]
How does FastHTML relate to FastAPI?
Expand Collapse
FastAPI is one of the inspirations for FastHTML. We are fans of its
developer experience and tried to make FastHTML extremely familiar
for FastAPI users. FastAPI is designed for creating APIs, whereas
FastHTML is designed for creating HTML (i.e "Hypermedia
applications"). Anything you could create with FastAPI (plus a JS
frontend), you could also create with FastHTML, and vice versa -- if
you prefer mainly writing JS, you might prefer FastAPI, since you can
move a lot of client-side logic into the JS. If you prefer mainly
writing Python, you'll probably want to use FastHTML, since you can
often avoid using JS entirely.
[ ]
Is this only for multi-page "old style" web apps, or can FastHTML be
used for modern SPA apps too?
Expand Collapse
FastHTML is specifically designed to make writing modern SPA apps as
fast and easy as possible, whilst also ensuring the apps you write
are scalable and performant. By default, FastHTML routes return
lightweight "partials" that update the DOM directly, rather than
doing a full page refresh.
[ ]
What is HTMX, and what's it go to do with FastHTML?
Expand Collapse
HTMX is best thought of as filling in the missing bits of a web
browser -- in fact, web browser manufacturers are considering
incorporating similar features directly into future browsers. It is a
small javascript library that with a single line of HTML lets you
respond to any event from any part of a web page by modifying the DOM
in any way you like, all directly from Python. Whilst you don't have
to use it with FastHTML, it will dramatically increase the amount of
stuff you can do!
[ ]
Do I need to know JS? Can I use it if I want, with FastHTML?
Expand Collapse
No, and yes! You can write nearly any standard web app with just
Python. However, using a bit of JS can be helpful -- for instance,
nearly any existing JS lib can be incorporated into a FastHTML app,
and you can sprinkle bits of JS into your pages anywhere you like.
[ ]
Are FastHTML apps slower than React, Next.JS, etc?
Expand Collapse
It depends. Apps using FastHTML and HTMX are often faster than
JS-based approaches using big libraries, since they can be very
lightweight.
LOVE IS IN THE AIR
What the experts say
Top web programmers tell us that they love working with FastHTML.
FastHTML is as intuitive as FastAPI, lends itself to clean
architecture, and its HTML+HTMX structure makes it a good competitor
to Django for building webapps. Most importantly, it's fun to use.
Picture of Daniel Roy Greenfeld
Daniel Roy Greenfeld
Co-author
Dot separator
Two Scoops of Django
Python has always been a wonderful tool for creating web
applications; with FastHTML, it's even better!
Picture of Giles Thomas
Giles Thomas
Founder
Dot separator
PythonAnywhere
With FastHTML and Railway, Pythonistas can now have a real web
application running in minutes, and can scale it all the way up to
sophisticated production deployments.
Picture of Jake Cooper
Jake Cooper
CEO
Dot separator
Railway.app
* ergonomic af
* fast af
* slick af
* SSR af
(From twitter)
Picture of Guillermo Rauch
Guillermo Rauch
CEO
Dot separator
Vercel
Arrow left Arrow left
(c) 2024 onwards AnswerDotAI. All rights reserved.
* Github Arrow right icon
* Join Discord Arrow right icon
* Docs Arrow right icon
* Site design Arrow right icon