python-fasthtml 0.14.24__tar.gz → 0.14.26__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. {python_fasthtml-0.14.24/python_fasthtml.egg-info → python_fasthtml-0.14.26}/PKG-INFO +1 -1
  2. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/__init__.py +3 -2
  3. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/core.py +5 -5
  4. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/jupyter.py +2 -2
  5. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/proxy.py +2 -2
  6. python_fasthtml-0.14.26/fasthtml/skill.py +23 -0
  7. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/pyproject.toml +3 -0
  8. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26/python_fasthtml.egg-info}/PKG-INFO +1 -1
  9. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/python_fasthtml.egg-info/SOURCES.txt +1 -0
  10. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/python_fasthtml.egg-info/entry_points.txt +3 -0
  11. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/tests/test_fh.py +4 -1
  12. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/CONTRIBUTING.md +0 -0
  13. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/LICENSE +0 -0
  14. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/MANIFEST.in +0 -0
  15. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/README.md +0 -0
  16. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/_modidx.py +0 -0
  17. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/authmw.py +0 -0
  18. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/basics.py +0 -0
  19. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/cli.py +0 -0
  20. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/common.py +0 -0
  21. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/components.py +0 -0
  22. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/components.pyi +0 -0
  23. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/core.pyi +0 -0
  24. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/fastapp.py +0 -0
  25. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/ft.py +0 -0
  26. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/js.py +0 -0
  27. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/katex.js +0 -0
  28. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/live_reload.py +0 -0
  29. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/oauth.py +0 -0
  30. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/pico.py +0 -0
  31. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/starlette.py +0 -0
  32. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/stripe_otp.py +0 -0
  33. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/svg.py +0 -0
  34. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/toaster.py +0 -0
  35. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/xtend.py +0 -0
  36. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/fasthtml/xtend.pyi +0 -0
  37. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/python_fasthtml.egg-info/dependency_links.txt +0 -0
  38. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/python_fasthtml.egg-info/requires.txt +0 -0
  39. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/python_fasthtml.egg-info/top_level.txt +0 -0
  40. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/setup.cfg +0 -0
  41. {python_fasthtml-0.14.24 → python_fasthtml-0.14.26}/tests/test_proxy.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-fasthtml
3
- Version: 0.14.24
3
+ Version: 0.14.26
4
4
  Summary: The fastest way to create an HTML app
5
5
  Author-email: Jeremy Howard and contributors <github@jhoward.fastmail.fm>
6
6
  License-Expression: Apache-2.0
@@ -3,7 +3,8 @@
3
3
  Modules:
4
4
 
5
5
  - `fasthtml.core`: The `FastHTML` subclass of `Starlette`.
6
- - `fasthtml.proxy`: Streaming HTTP responses and bidirectional WebSocket forwarding"""
6
+ - `fasthtml.proxy`: Streaming HTTP responses and bidirectional WebSocket forwarding
7
+ - `fasthtml.skill`: Write and review idiomatic FastHTML apps."""
7
8
 
8
- __version__ = "0.14.24"
9
+ __version__ = "0.14.26"
9
10
  from .core import *
@@ -569,16 +569,16 @@ htmx_exts = {
569
569
  "remove-me": "https://cdn.jsdelivr.net/npm/htmx-ext-remove-me@2.0.0/remove-me.js",
570
570
  "debug": "https://unpkg.com/htmx.org@1.9.12/dist/ext/debug.js",
571
571
  "ws": "https://cdn.jsdelivr.net/npm/htmx-ext-ws@2.0.3/ws.js",
572
- "ws4": "https://cdn.jsdelivr.net/npm/htmx.org@4.0.1/dist/ext/hx-ws.min.js",
572
+ "ws4": "https://cdn.jsdelivr.net/npm/htmx.org@4.0.2/dist/ext/hx-ws.min.js",
573
573
  "chunked-transfer": "https://cdn.jsdelivr.net/npm/htmx-ext-transfer-encoding-chunked@0.4.0/transfer-encoding-chunked.js",
574
- "sse4": "https://cdn.jsdelivr.net/npm/htmx.org@4.0.1/dist/ext/hx-sse.min.js",
575
- "live": "https://cdn.jsdelivr.net/npm/htmx.org@4.0.1/dist/ext/hx-live.min.js",
576
- "multipart": "https://cdn.jsdelivr.net/npm/htmx.org@4.0.1/dist/ext/hx-multipart.min.js"
574
+ "sse4": "https://cdn.jsdelivr.net/npm/htmx.org@4.0.2/dist/ext/hx-sse.min.js",
575
+ "live": "https://cdn.jsdelivr.net/npm/htmx.org@4.0.2/dist/ext/hx-live.min.js",
576
+ "multipart": "https://cdn.jsdelivr.net/npm/htmx.org@4.0.2/dist/ext/hx-multipart.min.js"
577
577
  }
578
578
 
579
579
  # %% ../nbs/api/00_core.ipynb #60cb52ea
580
580
  htmxsrc = Script(src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.7/dist/htmx.js")
581
- htmx4src = Script(src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.1/dist/htmx.min.js")
581
+ htmx4src = Script(src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.2/dist/htmx.min.js")
582
582
  fhjsscr = Script(src="https://cdn.jsdelivr.net/gh/answerdotai/fasthtml-js@1.0.13/fasthtml.js")
583
583
  surrsrc = Script(src="https://cdn.jsdelivr.net/gh/answerdotai/surreal@main/surreal.js")
584
584
  scopesrc = Script(src="https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js")
@@ -156,10 +156,10 @@ def HTMX(path="/", host='localhost', app=None, port=8000, height="auto", link=Fa
156
156
  def ws_client(app, nm='', host='localhost', port=8000, ws_connect='/ws', frame=True, link=True, **kwargs):
157
157
  path = f'/{nm}'
158
158
  c = Main('', cls="container", id=unqid())
159
+ ws_attrs = dict(hx_ws_connect=ws_connect) if app.htmx4 else dict(hx_ext='ws', ws_connect=ws_connect)
159
160
  @app.get(path)
160
161
  def f():
161
- return Div(c, id=nm or '_dest', hx_trigger='load',
162
- hx_ext="ws", ws_connect=ws_connect, **kwargs)
162
+ return Div(c, id=nm or '_dest', hx_trigger='load', **ws_attrs, **kwargs)
163
163
  if link: display(HTML(f'<a href="http://{host}:{port}{path}" target="_blank">open in browser</a>'))
164
164
  if frame: display(HTMX(path, host=host, port=port))
165
165
  def send(o): asyncio.create_task(app._send(o))
@@ -72,11 +72,11 @@ class ProxyResponse(Response):
72
72
  async def proxy_websocket(
73
73
  websocket, # Incoming Starlette WebSocket, not yet accepted
74
74
  url, # Complete upstream WebSocket URL, including query parameters
75
- headers=None, # Additional upstream handshake headers
75
+ headers=None, # Additional upstream headers, as a mapping or string/byte pairs
76
76
  ):
77
77
  "Relay text and binary frames until either peer disconnects."
78
78
  try:
79
- async with websockets.connect(url, additional_headers=headers,
79
+ async with websockets.connect(url, additional_headers=httpx2.Headers(headers).multi_items(),
80
80
  subprotocols=websocket.scope['subprotocols'] or None, max_size=None) as target:
81
81
  await websocket.accept(subprotocol=target.subprotocol)
82
82
  async def to_target():
@@ -0,0 +1,23 @@
1
+ # NB: this file is designed for an LLM reader, not a human. Add it to your LLM's context and ask it to explain.
2
+ r"""Write and review idiomatic FastHTML apps.
3
+
4
+ ## Read first
5
+
6
+ - index: https://www.fastht.ml/docs/llms.txt
7
+ - concise guide: https://www.fastht.ml/docs/ref/concise_guide.html.md
8
+ - handlers, binding, responses: https://www.fastht.ml/docs/ref/handlers.html.md
9
+ - routing: https://www.fastht.ml/docs/explains/routes.html.md
10
+ - role model: `examples/adv_app_strip.py`; https://raw.githubusercontent.com/AnswerDotAI/fasthtml/main/examples/adv_app_strip.py
11
+
12
+ ## Idioms
13
+
14
+ - FT: Python call; positional children, keyword attributes; return FT or tuple. No templates, serializers or JSON-rendering pipeline.
15
+ - `@rt`: function-name path; GET+POST default. Normally no verb restrictions. When needed, `@rt('/x')` + `def get(...)` infers GET; no redundant `methods=`.
16
+ - handler references: `hx_post=save`, `href=edit.to(id=record.id)`; no copied URL strings
17
+ - typed handler arguments bind form/query fields; `req`, `sess`, `auth` injected. No FastAPI `Depends`, `Form`, `response_model`.
18
+ - HTMX action → FT fragment; `target_id`, `hx_swap` on caller. Normal requests gain document boilerplate.
19
+ - components: small functions; record rendering: `__ft__`. No controller/form-class framework.
20
+ - `Titled`: title+H1+Container
21
+ - shared auth: Beforeware; authorize actions as well as pages
22
+ - `from fasthtml.common import *`; `app,rt = fast_app()`; `serve()`; no `__main__` guard
23
+ """
@@ -21,6 +21,9 @@ Documentation = "https://www.fastht.ml/docs/"
21
21
  [project.entry-points.nbdev]
22
22
  fasthtml = "fasthtml._modidx:d"
23
23
 
24
+ [project.entry-points.pyskills]
25
+ fasthtml = "fasthtml.skill"
26
+
24
27
  [project.optional-dependencies]
25
28
  dev = ['ipython', 'lxml', 'pysym2md>=0.0.6', 'monsterui', 'PyJWT', 'fastlite', 'pytest-asyncio']
26
29
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-fasthtml
3
- Version: 0.14.24
3
+ Version: 0.14.26
4
4
  Summary: The fastest way to create an HTML app
5
5
  Author-email: Jeremy Howard and contributors <github@jhoward.fastmail.fm>
6
6
  License-Expression: Apache-2.0
@@ -22,6 +22,7 @@ fasthtml/live_reload.py
22
22
  fasthtml/oauth.py
23
23
  fasthtml/pico.py
24
24
  fasthtml/proxy.py
25
+ fasthtml/skill.py
25
26
  fasthtml/starlette.py
26
27
  fasthtml/stripe_otp.py
27
28
  fasthtml/svg.py
@@ -4,3 +4,6 @@ fh_railway_link = fasthtml.cli:railway_link
4
4
 
5
5
  [nbdev]
6
6
  fasthtml = fasthtml._modidx:d
7
+
8
+ [pyskills]
9
+ fasthtml = fasthtml.skill
@@ -71,6 +71,7 @@ async def echo_http(request):
71
71
  async def echo_ws(ws):
72
72
  if status := ws.query_params.get('deny'): return await ws.send_denial_response(Response(status_code=int(status)))
73
73
  await ws.accept(subprotocol='echo')
74
+ await ws.send_text(ws.headers.get('x-api-token', ''))
74
75
  await ws.send_text(await ws.receive_text())
75
76
  await ws.send_bytes(await ws.receive_bytes())
76
77
  await ws.close(code=1000)
@@ -80,7 +81,8 @@ def test_proxy():
80
81
  with running_server(upstream) as url:
81
82
  async def forward_http(request):
82
83
  return ProxyResponse(request, url, headers=proxy_headers(request.headers, exclude=(b'authorization',)))
83
- async def forward_ws(ws): await proxy_websocket(ws, url.replace('http', 'ws')+'/ws?'+ws.url.query)
84
+ async def forward_ws(ws):
85
+ await proxy_websocket(ws, url.replace('http', 'ws')+'/ws?'+ws.url.query, headers=[(b'x-api-token', b'user:key')])
84
86
  app = Starlette(routes=[Route('/', forward_http, methods=['PATCH']), WebSocketRoute('/ws', forward_ws)])
85
87
  with TestClient(app) as proxy:
86
88
  body = b'["a", {"b":2}]'
@@ -93,6 +95,7 @@ def test_proxy():
93
95
  assert res.headers.get_list('x-tag') == ['a', 'b']
94
96
  with proxy.websocket_connect('/ws', subprotocols=['echo']) as ws:
95
97
  assert ws.accepted_subprotocol == 'echo'
98
+ assert ws.receive_text() == 'user:key'
96
99
  ws.send_text('hello')
97
100
  assert ws.receive_text() == 'hello'
98
101
  ws.send_bytes(b'\x00bytes')