Skip to content

Commit 7b613c8

Browse files
committed
update
1 parent f3416db commit 7b613c8

File tree

7 files changed

+145
-87
lines changed

7 files changed

+145
-87
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ repo’s notebooks and the official FastHTML examples repo:
138138
Then explore the small but growing third-party ecosystem of FastHTML
139139
tutorials, notebooks, libraries, and components:
140140

141-
- [FastHTML Gallery](https://fastht.ml/gallery): Learn from minimal
141+
- [FastHTML Gallery](https://gallery.fastht.ml): Learn from minimal
142142
examples of components (ie chat bubbles, click-to-edit, infinite
143143
scroll, etc)
144144
- [Creating Custom FastHTML Tags for Markdown

fasthtml/core.pyi

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""The `FastHTML` subclass of `Starlette`, along with the `RouterX` and `RouteX` classes it automatically uses."""
2-
__all__ = ['empty', 'htmx_hdrs', 'fh_cfg', 'htmx_resps', 'htmx_exts', 'htmxsrc', 'fhjsscr', 'surrsrc', 'scopesrc', 'viewport', 'charset', 'cors_allow', 'iframe_scr', 'all_meths', 'devtools_loc', 'parsed_date', 'snake2hyphens', 'HtmxHeaders', 'HttpHeader', 'HtmxResponseHeaders', 'form2dict', 'parse_form', 'JSONResponse', 'flat_xt', 'Beforeware', 'EventStream', 'signal_shutdown', 'uri', 'decode_uri', 'flat_tuple', 'noop_body', 'respond', 'is_full_page', 'Redirect', 'get_key', 'qp', 'def_hdrs', 'FastHTML', 'nested_name', 'serve', 'Client', 'RouteFuncs', 'APIRouter', 'cookie', 'reg_re_param', 'MiddlewareBase', 'FtResponse', 'unqid', 'setup_ws']
3-
import json, uuid, inspect, types, signal, asyncio, threading, inspect, random
2+
__all__ = ['empty', 'htmx_hdrs', 'fh_cfg', 'htmx_resps', 'htmx_exts', 'htmxsrc', 'fhjsscr', 'surrsrc', 'scopesrc', 'viewport', 'charset', 'cors_allow', 'iframe_scr', 'all_meths', 'devtools_loc', 'parsed_date', 'snake2hyphens', 'HtmxHeaders', 'HttpHeader', 'HtmxResponseHeaders', 'form2dict', 'parse_form', 'JSONResponse', 'flat_xt', 'Beforeware', 'EventStream', 'signal_shutdown', 'uri', 'decode_uri', 'flat_tuple', 'noop_body', 'respond', 'is_full_page', 'Redirect', 'get_key', 'qp', 'def_hdrs', 'FastHTML', 'nested_name', 'serve', 'Client', 'RouteFuncs', 'APIRouter', 'cookie', 'reg_re_param', 'MiddlewareBase', 'FtResponse', 'unqid']
3+
import json, uuid, inspect, types, signal, asyncio, threading, inspect, random, contextlib
44
from fastcore.utils import *
55
from fastcore.xml import *
66
from fastcore.meta import use_kwargs_dict
@@ -213,7 +213,7 @@ class Redirect:
213213

214214
async def _wrap_call(f, req, params):
215215
...
216-
htmx_exts = {'morph': 'https://cdn.jsdelivr.net/npm/idiomorph@0.7.3/dist/idiomorph-ext.min.js', 'head-support': 'https://cdn.jsdelivr.net/npm/htmx-ext-head-support@2.0.3/head-support.js', 'preload': 'https://cdn.jsdelivr.net/npm/htmx-ext-preload@2.1.0/preload.js', 'class-tools': 'https://cdn.jsdelivr.net/npm/htmx-ext-class-tools@2.0.1/class-tools.js', 'loading-states': 'https://cdn.jsdelivr.net/npm/htmx-ext-loading-states@2.0.0/loading-states.js', 'multi-swap': 'https://cdn.jsdelivr.net/npm/htmx-ext-multi-swap@2.0.0/multi-swap.js', 'path-deps': 'https://cdn.jsdelivr.net/npm/htmx-ext-path-deps@2.0.0/path-deps.js', 'remove-me': 'https://cdn.jsdelivr.net/npm/htmx-ext-remove-me@2.0.0/remove-me.js', 'ws': 'https://cdn.jsdelivr.net/npm/htmx-ext-ws@2.0.2/ws.js', 'chunked-transfer': 'https://cdn.jsdelivr.net/npm/htmx-ext-transfer-encoding-chunked@0.4.0/transfer-encoding-chunked.js'}
216+
htmx_exts = {'morph': 'https://cdn.jsdelivr.net/npm/idiomorph@0.7.3/dist/idiomorph-ext.min.js', 'head-support': 'https://cdn.jsdelivr.net/npm/htmx-ext-head-support@2.0.3/head-support.js', 'preload': 'https://cdn.jsdelivr.net/npm/htmx-ext-preload@2.1.0/preload.js', 'class-tools': 'https://cdn.jsdelivr.net/npm/htmx-ext-class-tools@2.0.1/class-tools.js', 'loading-states': 'https://cdn.jsdelivr.net/npm/htmx-ext-loading-states@2.0.0/loading-states.js', 'multi-swap': 'https://cdn.jsdelivr.net/npm/htmx-ext-multi-swap@2.0.0/multi-swap.js', 'path-deps': 'https://cdn.jsdelivr.net/npm/htmx-ext-path-deps@2.0.0/path-deps.js', 'remove-me': 'https://cdn.jsdelivr.net/npm/htmx-ext-remove-me@2.0.0/remove-me.js', 'ws': 'https://cdn.jsdelivr.net/npm/htmx-ext-ws@2.0.3/ws.js', 'chunked-transfer': 'https://cdn.jsdelivr.net/npm/htmx-ext-transfer-encoding-chunked@0.4.0/transfer-encoding-chunked.js'}
217217
htmxsrc = Script(src='https://cdn.jsdelivr.net/npm/htmx.org@2.0.4/dist/htmx.min.js')
218218
fhjsscr = Script(src='https://cdn.jsdelivr.net/gh/answerdotai/fasthtml-js@1.0.12/fasthtml.js')
219219
surrsrc = Script(src='https://cdn.jsdelivr.net/gh/answerdotai/surreal@main/surreal.js')
@@ -265,6 +265,9 @@ class FastHTML(Starlette):
265265
"""Add a route at `path`"""
266266
...
267267

268+
def set_lifespan(self, value):
269+
...
270+
268271
def static_route_exts(self, prefix='/', static_path='.', exts='static'):
269272
"""Add a static route at URL path `prefix` with files from `static_path` and `exts` defined by `reg_re_param()`"""
270273
...
@@ -273,6 +276,9 @@ class FastHTML(Starlette):
273276
"""Add a static route at URL path `prefix` with files from `static_path` and single `ext` (including the '.')"""
274277
...
275278

279+
def setup_ws(app, f=noop):
280+
...
281+
276282
def devtools_json(self, path=None, uuid=None):
277283
...
278284
all_meths = 'get post put delete patch head trace options'.split()
@@ -370,7 +376,4 @@ def unqid(seeded=False):
370376

371377
def _add_ids(s):
372378
...
373-
374-
def setup_ws(app, f=noop):
375-
...
376379
devtools_loc = '/.well-known/appspecific/com.chrome.devtools.json'

nbs/apilist.txt

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
- `def __call__(self, scope, receive, send)`
88
- `def authenticate(self, conn)`
99

10+
- `def user_pwd_auth(lookup, skip, **kwargs)`
11+
- `def basic_logout(request)`
1012
## fasthtml.cli
1113

1214
- `@call_parse def railway_link()`
@@ -19,6 +21,12 @@
1921

2022
> `ft_html` and `ft_hx` functions to add some conveniences to `ft`, along with a full set of basic HTML components, and functions to work with forms and `FT` conversion
2123

24+
- `@patch def __str__(self)`
25+
- `@patch def __radd__(self, b)`
26+
- `@patch def __add__(self, b)`
27+
- `def attrmap_x(o)`
28+
- `def ft_html(tag, *c, **kwargs)`
29+
- `@use_kwargs(hx_attrs + evt_attrs, keep=True) def ft_hx(tag, *c, **kwargs)`
2230
- `def File(fname)`
2331
Use the unescaped text in file `fname` directly
2432

@@ -34,6 +42,7 @@
3442
- `def find_inputs(e, tags, **kw)`
3543
Recursively find all elements in `e` with `tags` and attrs matching `kw`
3644

45+
- `def __getattr__(tag)`
3746
- `def html2ft(html, attr1st)`
3847
Convert HTML to an `ft` expression
3948

@@ -80,6 +89,11 @@
8089
- `def EventStream(s)`
8190
Create a text/event-stream response from `s`
8291

92+
- `def signal_shutdown()`
93+
- `def uri(_arg, **kwargs)`
94+
- `def decode_uri(s)`
95+
- `@patch def to_string(self, value)`
96+
- `@patch def url_path_for(self, name, **path_params)`
8397
- `def flat_tuple(o)`
8498
Flatten lists
8599

@@ -89,12 +103,14 @@
89103
- `def respond(req, heads, bdy)`
90104
Default FT response creation function
91105

106+
- `def is_full_page(req, resp)`
92107
- `class Redirect`
93108
Use HTMX or Starlette RedirectResponse as required to redirect to `loc`
94109

95110
- `def __init__(self, loc)`
96111
- `def __response__(self, req)`
97112

113+
- `def get_key(key, fname)`
98114
- `def qp(p, **kw)`
99115
Add parameters kw to path p
100116

@@ -103,8 +119,8 @@
103119

104120
- `class FastHTML`
105121
- `def __init__(self, debug, routes, middleware, title, exception_handlers, on_startup, on_shutdown, lifespan, hdrs, ftrs, exts, before, after, surreal, htmx, default_hdrs, sess_cls, secret_key, session_cookie, max_age, sess_path, same_site, sess_https_only, sess_domain, key_fname, body_wrap, htmlkw, nb_hdrs, canonical, **bodykw)`
106-
- `def add_route(self, route)`
107122

123+
- `@patch def add_route(self, route)`
108124
- `@patch def ws(self, path, conn, disconn, name, middleware)`
109125
Add a websocket route at `path`
110126

@@ -114,6 +130,7 @@
114130
- `@patch def route(self, path, methods, name, include_in_schema, body_wrap)`
115131
Add a route at `path`
116132

133+
- `@patch def set_lifespan(self, value)`
117134
- `def serve(appname, app, host, port, reload, reload_includes, reload_excludes)`
118135
Run the app in an async server, with live reload set as the default.
119136

@@ -146,6 +163,7 @@
146163
- `def cookie(key, value, max_age, expires, path, domain, secure, httponly, samesite)`
147164
Create a 'set-cookie' `HttpHeader`
148165

166+
- `def reg_re_param(m, s)`
149167
- `@patch def static_route_exts(self, prefix, static_path, exts)`
150168
Add a static route at URL path `prefix` with files from `static_path` and `exts` defined by `reg_re_param()`
151169

@@ -161,6 +179,9 @@
161179
- `def __init__(self, content, status_code, headers, cls, media_type, background)`
162180
- `def __response__(self, req)`
163181

182+
- `def unqid(seeded)`
183+
- `@patch def setup_ws(app, f)`
184+
- `@patch def devtools_json(self, path, uuid)`
164185
## fasthtml.fastapp
165186

166187
> The `fast_app` convenience wrapper
@@ -181,9 +202,11 @@
181202
- `def MarkdownJS(sel)`
182203
Implements browser-based markdown rendering.
183204

205+
- `def KatexMarkdownJS(sel, inline_delim, display_delim, math_envs)`
184206
- `def HighlightJS(sel, langs, light, dark)`
185207
Implements browser-based syntax highlighting. Usage example [here](/tutorials/quickstart_for_web_devs.html#code-highlighting).
186208

209+
- `def SortableJS(sel, ghost_class)`
187210
- `def MermaidJS(sel, theme)`
188211
Implements browser-based Mermaid diagram rendering.
189212

@@ -203,6 +226,8 @@
203226
- `def wait_port_free(port, host, max_wait)`
204227
Wait for `port` to be free on `host`
205228

229+
- `def render_ft()`
230+
- `def htmx_config_port(port)`
206231
- `class JupyUvi`
207232
Start and stop a Jupyter compatible uvicorn server with ASGI `app` on `port` with `log_level`
208233

@@ -218,11 +243,14 @@
218243
- `def start(self)`
219244
- `def stop(self)`
220245

221-
- `def HTMX(path, app, host, port, height, link, iframe)`
246+
- `def HTMX(path, host, app, port, height, link, iframe)`
222247
An iframe which displays the HTMX application in a notebook.
223248

249+
- `def ws_client(app, nm, host, port, ws_connect, frame, link, **kwargs)`
224250
## fasthtml.live_reload
225251

252+
- `def LiveReloadJs(reload_attempts, reload_interval, **kwargs)`
253+
- `def live_reload_ws(websocket)`
226254
- `class FastHTMLWithLiveReload`
227255
`FastHTMLWithLiveReload` enables live reloading.
228256
This means that any code changes saved on the server will automatically
@@ -299,6 +327,7 @@
299327
- `@patch def retr_id(self, code, redirect_uri)`
300328
Call `retr_info` and then return id/subscriber value
301329

330+
- `def url_match(url, patterns)`
302331
- `class OAuth`
303332
- `def __init__(self, app, cli, skip, redir_path, error_path, logout_path, login_path, https, http_patterns)`
304333
- `def redir_login(self, session)`
@@ -324,6 +353,7 @@
324353

325354
> Basic components for generating Pico CSS tags
326355

356+
- `def set_pico_cls()`
327357
- `@delegates(ft_hx, keep=True) def Card(*c, **kwargs)`
328358
A PicoCSS Card, implemented as an Article with optional Header and Footer
329359

@@ -342,6 +372,7 @@
342372
- `@delegates(ft_hx, keep=True) def Container(*args, **kwargs)`
343373
A PicoCSS Container, implemented as a Main with class 'container'
344374

375+
- `def PicoBusy()`
345376
## fasthtml.stripe_otp
346377

347378
- `def create_price(app_nm, amt, currency)`
@@ -350,8 +381,16 @@
350381
- `def archive_price(app_nm)`
351382
Archive a price - useful for cleanup if testing.
352383

384+
- `def before(sess)`
385+
- `@rt('/') def home(sess)`
386+
- `@rt('/create-checkout-session', methods=['POST']) def create_checkout_session(sess)`
353387
- `class Payment`
354388

389+
- `@rt('/webhook') def post(req)`
390+
- `@rt('/success') def success(sess, checkout_sid)`
391+
- `@rt('/cancel') def cancel()`
392+
- `@rt('/refund', methods=['POST']) def refund(sess, checkout_sid)`
393+
- `@rt('/account') def account_management(sess)`
355394
## fasthtml.svg
356395

357396
> Simple SVG FT elements
@@ -424,6 +463,13 @@
424463
- `def SvgInb(*args, **kwargs)`
425464
Wraps an SVG shape as required for an HTMX inband swap
426465

466+
## fasthtml.toaster
467+
468+
- `def Toast(message, typ, dismiss, duration)`
469+
- `def add_toast(sess, message, typ, dismiss)`
470+
- `def render_toasts(sess)`
471+
- `def toast_after(resp, req, sess)`
472+
- `def setup_toasts(app, duration)`
427473
## fasthtml.xtend
428474

429475
> Simple extensions to standard HTML components, such as adding sensible defaults
@@ -488,6 +534,7 @@
488534
- `def run_js(js, id, **kw)`
489535
Run `js` script, auto-generating `id` based on name of caller if needed, and js-escaping any `kw` params
490536

537+
- `def HtmxOn(eventname, code)`
491538
- `def jsd(org, repo, root, path, prov, typ, ver, esm, **kwargs)`
492539
jsdelivr `Script` or CSS `Link` tag, or URL
493540

@@ -508,3 +555,5 @@
508555
- `def Favicon(light_icon, dark_icon)`
509556
Light and dark favicon headers
510557

558+
- `def clear(id)`
559+
- `def with_sid(app, dest, path)`

nbs/index.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
"\n",
146146
"Then explore the small but growing third-party ecosystem of FastHTML tutorials, notebooks, libraries, and components:\n",
147147
"\n",
148-
"- [FastHTML Gallery](https://fastht.ml/gallery): Learn from minimal examples of components (ie chat bubbles, click-to-edit, infinite scroll, etc)\n",
148+
"- [FastHTML Gallery](https://gallery.fastht.ml): Learn from minimal examples of components (ie chat bubbles, click-to-edit, infinite scroll, etc)\n",
149149
"- [Creating Custom FastHTML Tags for Markdown Rendering](https://isaac-flath.github.io/website/posts/boots/FasthtmlTutorial.html) by Isaac Flath\n",
150150
"- [How to Build a Simple Login System in FastHTML](https://blog.mariusvach.com/posts/login-fasthtml) by Marius Vach\n",
151151
"- Your tutorial here!\n",

0 commit comments

Comments
 (0)