Code Monkey home page Code Monkey logo

fasthtml's Introduction

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.

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 title “FastHTML page” and the text “Hello World!”. Congratulations - you’ve just created your first fasthtml app!

Adding interactivity is surprisingly easy, thanks to HTMX. If you modify the file to add this function…:

main.py

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

…you’ll 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.

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:

fasthtml's People

Contributors

jph00 avatar pydanny avatar johnowhitaker avatar ncoop57 avatar audreyfeldroy avatar comhar avatar willingc avatar juanfrank77 avatar cthorrez avatar blackary avatar yuan-manx avatar siffogh avatar kafkasl avatar mathematicalmichael avatar matdmiller avatar vacmar01 avatar gerardwalsh avatar filiplajszczak avatar psabhay avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.