or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

application-routing.mdauthentication.mdcss-styling.mddevelopment-tools.mdform-handling.mdhtml-components.mdhtmx-integration.mdindex.mdjavascript-integration.mdnotifications.mdsvg-components.md
tile.json

tessl/pypi-python-fasthtml

The fastest way to create HTML apps - a next-generation Python web framework for building fast, scalable web applications with minimal code

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/python-fasthtml@0.12.x

To install, run

npx @tessl/cli install tessl/pypi-python-fasthtml@0.12.0

index.mddocs/

FastHTML

A next-generation Python web framework for building fast, scalable web applications with minimal code. FastHTML provides a powerful and expressive API that maps directly to HTML and HTTP, allowing developers to create advanced interactive web applications using pure Python.

Package Information

  • Package Name: python-fasthtml
  • Language: Python
  • Installation: pip install python-fasthtml
  • Version: 0.12.25

Core Imports

from fasthtml.common import *

This single import provides access to all core FastHTML functionality including:

  • Application creation and routing
  • All HTML elements as Python functions
  • HTMX integration for dynamic interactions
  • Form handling and data processing
  • Authentication and middleware
  • JavaScript library integration

For advanced usage, import specific modules:

from fasthtml.core import FastHTML, APIRouter, HtmxHeaders
from fasthtml.components import Div, P, H1, Form, Input
from fasthtml.xtend import AX, CheckboxX, Titled, Socials
from fasthtml.oauth import OAuth, GoogleAppClient, GitHubAppClient
from fasthtml.pico import Card, Grid, Container, picolink
from fasthtml.js import MarkdownJS, HighlightJS, SortableJS
from fasthtml.svg import Svg, Circle, Rect, Path, PathFT
from fasthtml.toaster import Toast, add_toast, setup_toasts
from fasthtml.jupyter import show, nb_serve, HTMX

Basic Usage

from fasthtml.common import *

# Create FastHTML app and router
app, rt = fast_app()

# Define routes using decorators
@rt('/')
def get():
    return Div(
        H1('Welcome to FastHTML'),
        P('Hello World!', hx_get="/change")
    )

@rt('/change')
def get():
    return P('Content changed!', style="color: green;")

# Start development server
serve()

Architecture

FastHTML is built on modern web development principles:

  • HTML as Code: Every HTML element is available as a Python function with the same name
  • HTMX Integration: Built-in support for dynamic web interactions without JavaScript
  • Starlette Foundation: Based on the fast, lightweight Starlette ASGI framework
  • Component System: Reusable UI components with enhanced functionality
  • Minimal Dependencies: Focused on essential web development tools

The framework emphasizes simplicity and speed, offering a lightweight solution that leverages the full Python ecosystem while maintaining intuitive syntax for rapid development.

Capabilities

Application Creation and Routing

Core functionality for creating FastHTML applications, defining routes, and handling HTTP requests. Includes the main FastHTML class, routing decorators, and development server.

def fast_app(
    db=None,
    render=None, 
    hdrs=None,
    ftrs=None,
    tbls=None,
    before=None,
    middleware=None,
    live=False,
    debug=False,
    routes=None,
    exception_handlers=None,
    on_startup=None,
    on_shutdown=None,
    lifespan=None,
    default_hdrs=True,
    pico=True,
    surreal=True,
    htmx=True,
    ws_hdr=False,
    secret_key=None,
    key_fname='.sesskey',
    session_cookie='session',
    max_age=365*24*3600,
    sess_path='/',
    same_site='lax',
    sess_https_only=False,
    sess_domain=None,
    htmlkw=None,
    **bodykw
) -> tuple[FastHTML, RouteFuncs]:
    """
    Create FastHTML app with sensible defaults and optional database integration.
    
    Returns:
        tuple: (FastHTML app instance, RouteFuncs for routing)
    """

def serve(
    appname=None,
    app='app',
    host='0.0.0.0',
    port=None,
    reload=True,
    reload_includes=None,
    reload_excludes=None
):
    """Start development server with hot reload."""

class FastHTML:
    """Main FastHTML application class (extends Starlette)."""
    
class RouteFuncs:
    """Dynamic route function container for HTTP methods."""

Application and Routing

HTML Components and Elements

Complete HTML element generation system with Python functions for every HTML tag. Includes enhanced components with HTMX integration and form handling capabilities.

def Div(*c, **kw):
    """Create HTML div element."""

def P(*c, **kw):
    """Create HTML paragraph element."""

def H1(*c, **kw):
    """Create HTML h1 heading element."""

def Form(*c, **kw):
    """Create HTML form element with enhanced functionality."""

def Input(*c, **kw):
    """Create HTML input element."""

def Button(*c, **kw):
    """Create HTML button element."""

HTML Components

HTMX Integration and Dynamic Interactions

Built-in HTMX support for creating dynamic, interactive web applications without writing JavaScript. Includes HTMX attributes, response handling, and event management.

class HtmxHeaders:
    """HTMX request headers dataclass."""
    hx_request: str
    hx_target: str
    hx_trigger: str
    hx_trigger_name: str
    hx_current_url: str
    
def ft_hx(tag, *c, **kw):
    """Create HTML element with HTMX support."""

HTMX Integration

Form Handling and Data Processing

Comprehensive form handling including data conversion, validation, file uploads, and dataclass integration.

def form2dict(form) -> dict:
    """Convert FormData to dictionary."""

def fill_form(form, obj):
    """Fill form with data object."""

def File(*c, **kw):
    """Handle file uploads."""

Form Handling

Authentication and Security

OAuth integration with multiple providers, basic authentication middleware, and session management.

class OAuth:
    """Main OAuth handler class."""
    
class BasicAuthMiddleware:
    """HTTP Basic authentication middleware."""

class GoogleAppClient:
    """Google OAuth integration."""

Authentication

CSS Framework Integration

Built-in PicoCSS integration with enhanced components and styling utilities for rapid UI development.

def Card(*c, **kw):
    """PicoCSS card component."""

def Grid(*c, **kw):
    """PicoCSS grid container."""

def Container(*c, **kw):
    """PicoCSS container."""

CSS and Styling

JavaScript Integration

Integration with popular JavaScript libraries including Markdown rendering, syntax highlighting, and interactive components.

def MarkdownJS(*c, **kw):
    """Markdown parsing and rendering."""

def HighlightJS(*c, **kw):
    """Syntax highlighting."""

def SortableJS(*c, **kw):
    """Drag-and-drop sorting."""

JavaScript Integration

SVG Components and Graphics

Comprehensive SVG element generation system for creating scalable vector graphics, charts, diagrams, and interactive visualizations.

def Svg(*args, viewBox=None, xmlns="http://www.w3.org/2000/svg", **kwargs):
    """SVG root element with automatic xmlns namespace."""

def Rect(width, height, x=0, y=0, fill=None, stroke=None, **kwargs):
    """SVG rectangle element."""

def Circle(r, cx=0, cy=0, fill=None, stroke=None, **kwargs):
    """SVG circle element."""

def Path(d='', fill=None, stroke=None, **kwargs):
    """SVG path element for complex shapes."""

SVG Components

Notifications and Toast Messages

User notification system with toast messages, flash messages, and session-based notification management for enhanced user experience.

def Toast(message: str, typ: str = "info", dismiss: bool = False, duration: int = 5000):
    """Create toast notification message."""

def add_toast(sess, message: str, typ: str = "info", dismiss: bool = False):
    """Add toast notification to user session."""

def setup_toasts(app, duration: int = 5000):
    """Set up toast notification system in FastHTML app."""

Notifications

Development Tools

Development server with live reload, Jupyter notebook integration, testing utilities, and deployment tools.

def show(ft):
    """Display FastHTML elements in Jupyter."""

class Client:
    """HTTP client for testing FastHTML apps."""

def nb_serve():
    """Start Jupyter-compatible server."""

Development Tools