Skip to content

Commit

Permalink
deploy: 978f858
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed May 17, 2024
0 parents commit 44cfd1e
Show file tree
Hide file tree
Showing 23 changed files with 6,391 additions and 0 deletions.
Empty file added .nojekyll
Empty file.
837 changes: 837 additions & 0 deletions core.html

Large diffs are not rendered by default.

635 changes: 635 additions & 0 deletions index.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sitemap: https://AnswerDotAI.github.io/fasthtml/sitemap.xml
52 changes: 52 additions & 0 deletions search.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[
{
"objectID": "index.html",
"href": "index.html",
"title": "fasthtml",
"section": "",
"text": "pip install fasthtml",
"crumbs": [
"fasthtml"
]
},
{
"objectID": "index.html#install",
"href": "index.html#install",
"title": "fasthtml",
"section": "",
"text": "pip install fasthtml",
"crumbs": [
"fasthtml"
]
},
{
"objectID": "index.html#how-to-use",
"href": "index.html#how-to-use",
"title": "fasthtml",
"section": "How to use",
"text": "How to use\nFill me in please! Don’t forget code examples:\n\n1+1\n\n2",
"crumbs": [
"fasthtml"
]
},
{
"objectID": "core.html",
"href": "core.html",
"title": "FastHTML",
"section": "",
"text": "from IPython import display\nfrom enum import Enum\nfrom pprint import pprint\n\nfrom starlette.testclient import TestClient\n# if 'HX-Request' not in request.headers:\n# resp = wrap_root(resp, self.headtags)\nsource",
"crumbs": [
"FastHTML"
]
},
{
"objectID": "core.html#demo",
"href": "core.html#demo",
"title": "FastHTML",
"section": "Demo",
"text": "Demo\n\ndef todict(req): return {k:str(v) for k,v in req.items()}\n\n\napp = FastHTML()\n\[email protected](\"/\")\ndef root(req): return todict(req.scope)\n\[email protected]('/user/{nm}')\ndef get_nm(nm:str): return f\"Good day to you, {nm}!\"\n\n\nclient = TestClient(app)\nr = client.get('/')\nprint(r.text)\n\n{\"type\":\"http\",\"http_version\":\"1.1\",\"method\":\"GET\",\"path\":\"/\",\"raw_path\":\"b'/'\",\"root_path\":\"\",\"scheme\":\"http\",\"query_string\":\"b''\",\"headers\":\"[(b'host', b'testserver'), (b'accept', b'*/*'), (b'accept-encoding', b'gzip, deflate, br'), (b'connection', b'keep-alive'), (b'user-agent', b'testclient')]\",\"client\":\"['testclient', 50000]\",\"server\":\"['testserver', 80]\",\"extensions\":\"{'http.response.debug': {}}\",\"state\":\"{}\",\"app\":\"<starlette.applications.Starlette object>\",\"starlette.exception_handlers\":\"({<class 'starlette.exceptions.HTTPException'>: <bound method ExceptionMiddleware.http_exception of <starlette.middleware.exceptions.ExceptionMiddleware object>>, <class 'starlette.exceptions.WebSocketException'>: <bound method ExceptionMiddleware.websocket_exception of <starlette.middleware.exceptions.ExceptionMiddleware object>>}, {})\",\"router\":\"<starlette.routing.Router object>\",\"endpoint\":\"<function _wrap_ep.<locals>._f>\",\"path_params\":\"{}\"}\n\n\n\nclient.get('/user/jph').text\n\n'Good day to you, jph!'\n\n\n\[email protected]('/html/{idx}')\nasync def get_html(idx:int):\n return Body(\n H4(\"Wow look here\"),\n P(f'It looks like you are visitor {idx}! Next is {idx+1}.')\n )\n\n\ndisplay.HTML(client.get('/html/1').text)\n\n\n \nWow look here\n \n \nIt looks like you are visitor 1! Next is 2.\n \n\n\n\n\nModelName = str_enum('ModelName', \"alexnet\", \"resnet\", \"lenet\")\n\napp = FastHTML()\[email protected](\"/models/{nm}\")\ndef model(nm:ModelName): return nm\n\[email protected](\"/files/{path}\")\nasync def txt(path: Path): return path.with_suffix('.txt')\n\n\nprint(TestClient(app).get('/models/alexnet').text)\n\nalexnet\n\n\n\nprint(TestClient(app).get('/files/foo').text)\n\nfoo.txt\n\n\n\nfake_db = [{\"name\": \"Foo\"}, {\"name\": \"Bar\"}]\n\[email protected](\"/items/\")\ndef read_item(idx:int|None = 0): return fake_db[idx]\n\n\nprint(TestClient(app).get('/items/?idx=1').text)\n\n{\"name\":\"Bar\"}\n\n\n\nprint(TestClient(app).get('/items/').text)\n\n{\"name\":\"Foo\"}\n\n\n\[email protected](\"/booly/\")\ndef booly(coming:bool=True): return 'Coming' if coming else 'Not coming'\n\n\ncli = TestClient(app)\nprint(cli.get('/booly/?coming=true').text)\n\nComing\n\n\n\nprint(cli.get('/booly/?coming=no').text)\n\nNot coming\n\n\n\[email protected](\"/datie/\")\ndef datie(d:date): return d\n\n\ncli = TestClient(app)\ndate_str = \"17th of May, 2024, 2p\"\nprint(cli.get(f'/datie/?d={date_str}').text)\n\n2024-05-17 14:00:00\n\n\n\n@dataclass\nclass Bodie:\n a:int;b:str\n\n\[email protected](\"/bodie/{nm}/\")\nasync def bodie(nm:str, data:Bodie):\n res = asdict(data)\n res['nm'] = nm\n return res\n\n\ncli.post('/bodie/me', data=dict(a=1, b='foo')).text\n\n'{\"a\":1,\"b\":\"foo\",\"nm\":\"me\"}'\n\n\n\[email protected](\"/setcookie\")\nasync def setc(req):\n now = datetime.now()\n res = Response(f'Set to {now}')\n res.set_cookie('now', str(now))\n return res\n\n\ncli.get('/setcookie').text\n\n'Set to 2024-05-17 15:23:30.099808'\n\n\n\[email protected](\"/getcookie\")\nasync def getc(now:date): return f'Cookie was set at time {now.time()}'\n\n\ncli.get('/getcookie').text\n\n'Cookie was set at time 15:23:30.099808'\n\n\n\[email protected](\"/ua\")\nasync def ua(user_agent:str): return user_agent\n\n\ncli.get('/ua', headers={'User-Agent':'FastHTML'}).text\n\n'FastHTML'",
"crumbs": [
"FastHTML"
]
}
]
Loading

0 comments on commit 44cfd1e

Please sign in to comment.