FastHTML

FastHTML: The Perfect Framework for Simple AI-Powered Web Apps?

I heard about FastHTML a few months back and was immediately intrigued by its pitch:

“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.”

https://www.fastht.ml/

This sounded like something I could use!

But I’m wary of new frameworks. Few of them become popular enough long-term to really be worth your time. Was this just another one that people might get excited about, but that would ultimately fade away?

I’ve been using Django as my go-to platform for building LLM-based applications for a while now and it’s amazing (I’m a fan of Ruby on Rails, too, but switched to Python for AI-centric projects.) With so many people using it, you can be confident of finding built-in support or 3rd-party libraries and documentation for any common task.

But Django also feels quite cumbersome for small applications. A more lightweight option with a simple way to achieve some basic front-end effects could be a handy tool to have available.

I was keen to give this new framework a go.

Well – I’ve finally had a chance to do that. Here are some quick notes on how I found it.

Getting Started

Possibly the best thing about FastHTML is how easy it is to get started. It really is very straightforward to follow their instructions and get something up and running locally. It probably took me a few minutes. And as it hooks into HTMX out of the box, you can set up some handy and effective frontend UI effects very easily.

Building an MVP

This was a very simple app without any authentication or a relational database to interact with, so there were lots of common web app tasks that I didn’t have to go through.

I just needed to show a page with a simple form, respond to form submissions, do some back-end processing, and call out to some other services – nothing too challenging. FastHTML handled the web UI aspects perfectly in exactly the lightweight way I’d hoped.

Getting Ready for Production

Moving to production, things mostly went smoothly but I did hit one limitation with FastHTML. I was using TailwindCSS for styling and using Tailwind to generate streamlined versions of my main CSS file with just the styles I needed. Doing this reduced the page load size by 330 kB which wasn’t too critical in this case but turned out to be an interesting experiment in any case. Anyhow, this meant the CSS file was frequently being updated as I tweaked styling.

In production, browsers would cache an old version of the CSS file and end up with incorrect styling. This is a well-known problem and frameworks such as Rails and Django have out-of-the-box solutions to address it. At the moment, FastHTML doesn’t seem to. It’s not a major issue, but an example of the kind of hassle that you can largely avoid with more mature frameworks.

Deployment

Deploying my FastHTML app was fairly straightforward though did require a bit of figuring out on my part. I got my app running on a Digital Ocean’s App Platform after a bit of research into their ‘app specs‘ and making appropriate tweaks. If the FastHTML framework continues to gain in popularity, I expect hosting companies will make framework-specific tweaks and provide documentation that will make the process even more streamlined.

Conclusions

If you’re familiar with Python and wanting to build a fairly simple ‘GPT wrapper’ kind of web app, then I highly recommend taking a look at FastHTML. It’s great for creating MVPs of that kind of thing.

If you’re looking to build something a bit more complicated, then I’d be wary for now – you might like to wait a bit for the framework and the ecosystem around it to mature as I suspect you’ll hit limitations somewhere or another.

All in all, though, FastHTML is looking very promising. I think the philosophy behind it makes a lot of sense and, judging by the activity around it already, it seems like plenty of other people feel likewise. Congratulations to Jeremy Howard (the main person behind it) and everyone else who’s contributed to it so far!

P.S. In case you’d like to see the little app I created, here it is!


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *