python-fasthtml


Namepython-fasthtml JSON
Version 0.10.1 PyPI version JSON
download
home_pagehttps://github.com/AnswerDotAI/fasthtml
SummaryThe fastest way to create an HTML app
upload_time2024-12-01 23:52:16
maintainerNone
docs_urlNone
authorJeremy Howard and contributors
requires_python>=3.10
licenseApache Software License 2.0
keywords nbdev jupyter notebook python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # FastHTML


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

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:
[about.fastht.ml](https://about.fastht.ml/).

## Installation

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

``` sh
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:

<div class="code-with-filename">

**main.py**

``` python
from fasthtml.common import *

app,rt = fast_app()

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

serve()
```

</div>

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:

<div class="code-with-filename">

**main.py**

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

</div>

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:

- [/llms-ctx.txt](https://docs.fastht.ml/llms-ctx.txt)

This example is in a format based on recommendations from Anthropic for
use with [Claude
Projects](https://support.anthropic.com/en/articles/9517075-what-are-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](https://gist.github.com/jph00/9559b0a563f6a370029bec1d1cc97b74)
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`](https://llmstxt.org/) (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](https://about.fastht.ml): Learn about the core ideas behind
  FastHTML
- [Documentation](https://docs.fastht.ml): Learn from examples how to
  write FastHTML code
- [Idiomatic
  app](https://github.com/AnswerDotAI/fasthtml/blob/main/examples/adv_app.py):
  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:

- [FastHTML Examples Repo on
  GitHub](https://github.com/AnswerDotAI/fasthtml-example)
- [FastHTML Repo on GitHub](https://github.com/AnswerDotAI/fasthtml)

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

- [FastHTML Gallery](https://gallery.fastht.ml): Learn from minimal
  examples of components (ie chat bubbles, click-to-edit, infinite
  scroll, etc)
- [Creating Custom FastHTML Tags for Markdown
  Rendering](https://isaac-flath.github.io/website/posts/boots/FasthtmlTutorial.html)
  by Isaac Flath
- [How to Build a Simple Login System in
  FastHTML](https://blog.mariusvach.com/posts/login-fasthtml) by Marius
  Vach
- Your tutorial here!

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

- [Discord](https://discord.gg/qcXvcxMhdP)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/AnswerDotAI/fasthtml",
    "name": "python-fasthtml",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "nbdev jupyter notebook python",
    "author": "Jeremy Howard and contributors",
    "author_email": "github@jhoward.fastmail.fm",
    "download_url": "https://files.pythonhosted.org/packages/3c/04/01b730f51d657cfc0ed252e4378b1fda3762662a5cabc1fdb392d2c134a6/python-fasthtml-0.10.1.tar.gz",
    "platform": null,
    "description": "# FastHTML\n\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\nWelcome to the official FastHTML documentation.\n\nFastHTML is a new next-generation web framework for fast, scalable web\napplications with minimal, compact code. It\u2019s designed to be:\n\n- Powerful and expressive enough to build the most advanced, interactive\n  web apps you can imagine.\n- Fast and lightweight, so you can write less code and get more done.\n- Easy to learn and use, with a simple, intuitive syntax that makes it\n  easy to build complex apps quickly.\n\nFastHTML apps are just Python code, so you can use FastHTML with the\nfull power of the Python language and ecosystem. FastHTML\u2019s\nfunctionality maps 1:1 directly to HTML and HTTP, but allows them to be\nencapsulated using good software engineering practices\u2014so you\u2019ll need to\nunderstand these foundations to use this library fully. To understand\nhow and why this works, please read this first:\n[about.fastht.ml](https://about.fastht.ml/).\n\n## Installation\n\nSince `fasthtml` is a Python library, you can install it with:\n\n``` sh\npip install python-fasthtml\n```\n\nIn the near future, we hope to add component libraries that can likewise\nbe installed via `pip`.\n\n## Usage\n\nFor a minimal app, create a file \u201cmain.py\u201d as follows:\n\n<div class=\"code-with-filename\">\n\n**main.py**\n\n``` python\nfrom fasthtml.common import *\n\napp,rt = fast_app()\n\n@rt('/')\ndef get(): return Div(P('Hello World!'), hx_get=\"/change\")\n\nserve()\n```\n\n</div>\n\nRunning the app with `python main.py` prints out a link to your running\napp: `http://localhost:5001`. Visit that link in your browser and you\nshould see a page with the text \u201cHello World!\u201d. Congratulations, you\u2019ve\njust created your first FastHTML app!\n\nAdding interactivity is surprisingly easy, thanks to HTMX. Modify the\nfile to add this function:\n\n<div class=\"code-with-filename\">\n\n**main.py**\n\n``` python\n@rt('/change')\ndef get(): return P('Nice to be here!')\n```\n\n</div>\n\nYou now have a page with a clickable element that changes the text when\nclicked. When clicking on this link, the server will respond with an\n\u201cHTML partial\u201d\u2014that is, just a snippet of HTML which will be inserted\ninto the existing page. In this case, the returned element will replace\nthe original P element (since that\u2019s the default behavior of HTMX) with\nthe new version returned by the second route.\n\nThis \u201chypermedia-based\u201d approach to web development is a powerful way to\nbuild web applications.\n\n### Getting help from AI\n\nBecause FastHTML is newer than most LLMs, AI systems like Cursor,\nChatGPT, Claude, and Copilot won\u2019t give useful answers about it. To fix\nthat problem, we\u2019ve provided an LLM-friendly guide that teaches them how\nto use FastHTML. To use it, add this link for your AI helper to use:\n\n- [/llms-ctx.txt](https://docs.fastht.ml/llms-ctx.txt)\n\nThis example is in a format based on recommendations from Anthropic for\nuse with [Claude\nProjects](https://support.anthropic.com/en/articles/9517075-what-are-projects).\nThis works so well that we\u2019ve actually found that Claude can provide\neven better information than our own documentation! For instance, read\nthrough [this annotated Claude\nchat](https://gist.github.com/jph00/9559b0a563f6a370029bec1d1cc97b74)\nfor some great getting-started information, entirely generated from a\nproject using the above text file as context.\n\nIf you use Cursor, type `@doc` then choose \u201c*Add new doc*\u201d, and use the\n/llms-ctx.txt link above. The context file is auto-generated from our\n[`llms.txt`](https://llmstxt.org/) (our proposed standard for providing\nAI-friendly information)\u2014you can generate alternative versions suitable\nfor other models as needed.\n\n## Next Steps\n\nStart with the official sources to learn more about FastHTML:\n\n- [About](https://about.fastht.ml): Learn about the core ideas behind\n  FastHTML\n- [Documentation](https://docs.fastht.ml): Learn from examples how to\n  write FastHTML code\n- [Idiomatic\n  app](https://github.com/AnswerDotAI/fasthtml/blob/main/examples/adv_app.py):\n  Heavily commented source code walking through a complete application,\n  including custom authentication, JS library connections, and database\n  use.\n\nWe also have a 1-hour intro video:\n\n<https://www.youtube.com/embed/Auqrm7WFc0I>\n\nThe capabilities of FastHTML are vast and growing, and not all the\nfeatures and patterns have been documented yet. Be prepared to invest\ntime into studying and modifying source code, such as the main FastHTML\nrepo\u2019s notebooks and the official FastHTML examples repo:\n\n- [FastHTML Examples Repo on\n  GitHub](https://github.com/AnswerDotAI/fasthtml-example)\n- [FastHTML Repo on GitHub](https://github.com/AnswerDotAI/fasthtml)\n\nThen explore the small but growing third-party ecosystem of FastHTML\ntutorials, notebooks, libraries, and components:\n\n- [FastHTML Gallery](https://gallery.fastht.ml): Learn from minimal\n  examples of components (ie chat bubbles, click-to-edit, infinite\n  scroll, etc)\n- [Creating Custom FastHTML Tags for Markdown\n  Rendering](https://isaac-flath.github.io/website/posts/boots/FasthtmlTutorial.html)\n  by Isaac Flath\n- [How to Build a Simple Login System in\n  FastHTML](https://blog.mariusvach.com/posts/login-fasthtml) by Marius\n  Vach\n- Your tutorial here!\n\nFinally, join the FastHTML community to ask questions, share your work,\nand learn from others:\n\n- [Discord](https://discord.gg/qcXvcxMhdP)\n",
    "bugtrack_url": null,
    "license": "Apache Software License 2.0",
    "summary": "The fastest way to create an HTML app",
    "version": "0.10.1",
    "project_urls": {
        "Homepage": "https://github.com/AnswerDotAI/fasthtml"
    },
    "split_keywords": [
        "nbdev",
        "jupyter",
        "notebook",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8dd4c416632e7189b85a2cb0a81a845c8de1c4178bc64151a0d7c78698167229",
                "md5": "cdcbced527bc6fd2da64a11d9436cdbb",
                "sha256": "93e75bc540c226ffec559ba69c92fb78b6d62ee45842787fdb71e455c4d88c3f"
            },
            "downloads": -1,
            "filename": "python_fasthtml-0.10.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cdcbced527bc6fd2da64a11d9436cdbb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 58846,
            "upload_time": "2024-12-01T23:52:13",
            "upload_time_iso_8601": "2024-12-01T23:52:13.740822Z",
            "url": "https://files.pythonhosted.org/packages/8d/d4/c416632e7189b85a2cb0a81a845c8de1c4178bc64151a0d7c78698167229/python_fasthtml-0.10.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3c0401b730f51d657cfc0ed252e4378b1fda3762662a5cabc1fdb392d2c134a6",
                "md5": "3f585528fa2b3b7c66344b7d52d45e8a",
                "sha256": "1e635394f93a192d7c1d360cb24ce815f5d10b93a3567ebc8c4076bed21a162d"
            },
            "downloads": -1,
            "filename": "python-fasthtml-0.10.1.tar.gz",
            "has_sig": false,
            "md5_digest": "3f585528fa2b3b7c66344b7d52d45e8a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 55508,
            "upload_time": "2024-12-01T23:52:16",
            "upload_time_iso_8601": "2024-12-01T23:52:16.036593Z",
            "url": "https://files.pythonhosted.org/packages/3c/04/01b730f51d657cfc0ed252e4378b1fda3762662a5cabc1fdb392d2c134a6/python-fasthtml-0.10.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-01 23:52:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AnswerDotAI",
    "github_project": "fasthtml",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "python-fasthtml"
}
        
Elapsed time: 0.37656s