FastApp
The fast_app convenience wrapper for creating FastHTML apps and optional SQLite tables
fast_app creates a configured FastHTML application (or FastHTMLWithLiveReload when live=True), its route decorator, and optional fastlite SQLite tables in one call.
app, rt = fast_app()
@rt
def index(): return Titled('Home', P('Hello'))
serve()
fast_app
def fast_app(
db_file:Optional[str]=None, # Database file name, if needed
render:Optional[<built-in function callable>]=None, # Function used to render default database class
hdrs:Optional[tuple]=None, # Additional FT elements to add to <HEAD>
ftrs:Optional[tuple]=None, # Additional FT elements to add to end of <BODY>
tbls:Optional[dict]=None, # Experimental mapping from DB table names to dict table definitions
before:Union[tuple, NoneType, fasthtml.core.Beforeware]=None, # Functions to call prior to calling handler
middleware:Optional[tuple]=None, # Standard Starlette middleware
live:bool=False, # Enable live reloading
debug:bool=False, # Passed to Starlette, indicating if debug tracebacks should be returned on errors
title:str='FastHTML page', # Default page title
routes:Optional[tuple]=None, # Passed to Starlette
exception_handlers:Optional[dict]=None, # Passed to Starlette
on_startup:Optional[<built-in function callable>]=None, # Passed to Starlette
on_shutdown:Optional[<built-in function callable>]=None, # Passed to Starlette
lifespan:Optional[<built-in function callable>]=None, # Passed to Starlette
default_hdrs:bool=True, # Include default FastHTML headers such as HTMX script?
pico:Optional[bool]=None, # Include PicoCSS header?
surreal:Optional[bool]=True, # Include surreal.js/scope headers?
htmx:Optional[bool]=True, # Include HTMX header?
htmx4:Optional[bool]=True, # Use HTMX 4? (False for legacy HTMX 2)
htmx_cfg:Optional[dict]=None, # Overrides for HTMX 4 htmx-config meta tag
exts:Union[list, str, NoneType]=None, # HTMX extension names to include
canonical:bool=True, # Automatically include canonical link?
secret_key:Optional[str]=None, # Signing key for sessions
key_fname:str='.sesskey', # Session cookie signing key file name
session_cookie:str='session_', # Session cookie name
max_age:int=31536000, # Session cookie expiry time
sess_path:str='/', # Session cookie path
same_site:str='lax', # Session cookie same site policy
sess_https_only:bool=False, # Session cookie HTTPS only?
sess_domain:Optional[str]=None, # Session cookie domain
htmlkw:Optional[dict]=None, # Attrs to add to the HTML tag
bodykw:Optional[dict]=None, # Attrs to add to the Body tag
reload_attempts:Optional[int]=1, # Number of reload attempts when live reloading
reload_interval:Optional[int]=1000, # Time between reload attempts in ms
static_path:str='.', # Where the static file route points to, defaults to root dir
body_wrap:<built-in function callable>=noop_body, # FT wrapper for body contents
nb_hdrs:bool=False, # If in notebook include headers inject headers in notebook DOM?
**kwargs
):
Create a FastHTML or FastHTMLWithLiveReload app, returning (app, app.route) when db_file is None.
When db_file is given, opens it with fastlite.database, creates or migrates tables from tbls or kwargs (dict-valued kwargs create one table each; column-type kwargs create a single items table with render bound as dc.__ft__), and returns (app, rt, tbl, dc) for one table or (app, rt, (tbl1, dc1), ...) for multiple.