Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fasthtml/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ def devtools(): return dict(workspace=dict(root=str(path), uuid=uuid))
# %% ../nbs/api/00_core.ipynb #e27908c0
@patch
def get_client(self:FastHTML, asink=False, **kw):
"Get an httpx client with session cookes set from `**kw`"
"Get an httpx client with session cookies set from `**kw`"
import httpx2
signer = itsdangerous.TimestampSigner(self.secret_key)
data = b64encode(dumps(kw).encode())
Expand Down
2 changes: 1 addition & 1 deletion fasthtml/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class FastHTML(Starlette):
...

def get_client(self, asink=False, **kw):
"""Get an httpx client with session cookes set from `**kw`"""
"""Get an httpx client with session cookies set from `**kw`"""
...

def decode_session(self, cookie):
Expand Down
2 changes: 1 addition & 1 deletion nbs/api/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5145,7 +5145,7 @@
"#| export\n",
"@patch\n",
"def get_client(self:FastHTML, asink=False, **kw):\n",
" \"Get an httpx client with session cookes set from `**kw`\"\n",
" \"Get an httpx client with session cookies set from `**kw`\"\n",
" import httpx2\n",
" signer = itsdangerous.TimestampSigner(self.secret_key)\n",
" data = b64encode(dumps(kw).encode())\n",
Expand Down
2 changes: 1 addition & 1 deletion nbs/api/06_jupyter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"metadata": {},
"outputs": [],
"source": [
"from httpx import get, AsyncClient"
"from httpx2 import get, AsyncClient"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion nbs/apilist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
- `@patch def setup_ws(app, f)`
- `@patch def devtools_json(self, path, uuid)`
- `@patch def get_client(self, asink, **kw)`
Get an httpx client with session cookes set from `**kw`
Get an httpx client with session cookies set from `**kw`

- `@patch def decode_session(self, cookie)`
Decode a signed session cookie
Expand Down
5 changes: 3 additions & 2 deletions nbs/explains/background_tasks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@
"```python\n",
"# main.py\n",
"from fasthtml.common import *\n",
"from fastlite import *\n",
"from starlette.background import BackgroundTask\n",
"import time\n",
"import httpx\n",
"import httpx2\n",
"\n",
"app, rt = fast_app()\n",
"\n",
Expand All @@ -172,7 +173,7 @@
"tstamps = db.create(TStamp, pk='request_time')\n",
"\n",
"def task_submit(request_time: int): # <2>\n",
" client = httpx.Client()\n",
" client = httpx2.Client()\n",
" response = client.post(f'http://127.0.0.1:8123/slow?ts={request_time}') # <3>\n",
" tstamps.insert(**response.json()) # <4>\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion nbs/explains/explaining_xt_components.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@
"source": [
"If you use type hints, we strongly suggest that FT components be treated as the `Any` type.\n",
"\n",
"The reason is that FastHTML leverages python's dynamic features to a great degree. Especially when it comes to `FT` components, which can evaluate out to be `FT|str|None|tuple` as well as anything that supports the `__ft__`, `__html__`, and `__str__` method. That's enough of the Python stack that assigning anything but `Any` to be the FT type will prove an exercise in frustation."
"The reason is that FastHTML leverages python's dynamic features to a great degree. Especially when it comes to `FT` components, which can evaluate out to be `FT|str|None|tuple` as well as anything that supports the `__ft__`, `__html__`, and `__str__` method. That's enough of the Python stack that assigning anything but `Any` to be the FT type will prove an exercise in frustration."
]
}
],
Expand Down
45 changes: 12 additions & 33 deletions nbs/explains/faq.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,32 @@
"id": "5c34ab11",
"metadata": {},
"source": [
"Many editors, including Visual Studio Code, use PyLance to provide error checking for Python. However, PyLance's error checking is just a guess -- it can't actually know whether your code is correct or not. PyLance particularly struggles with FastHTML's syntax, which leads to it often reporting false error messages in FastHTML projects.\n",
"Many editors, including Visual Studio Code, use Pylance to provide error checking for Python. However, Pylance's error checking is just a guess -- it can't actually know whether your code is correct or not. Pylance particularly struggles with FastHTML's syntax, which leads to it often reporting false error messages in FastHTML projects.\n",
"\n",
"To avoid these misleading error messages, it's best to disable some PyLance error checking in your FastHTML projects. Here's how to do it in Visual Studio Code (the same approach should also work in other editors based on vscode, such as Cursor and GitHub Codespaces):\n",
"To avoid these misleading error messages, it's best to disable some Pylance error checking in your FastHTML projects. Here's how to do it in Visual Studio Code (the same approach should also work in other editors based on VS Code, such as Cursor and GitHub Codespaces):\n",
"\n",
"1. Open your FastHTML project\n",
"2. Press `Ctrl+Shift+P` (or `Cmd+Shift+P` on Mac) to open the Command Palette\n",
"3. Type \"Preferences: Open Workspace Settings (JSON)\" and select it\n",
"4. In the JSON file that opens, add the following lines:\n",
"```json\n",
"{\n",
" \"python.analysis.diagnosticSeverityOverrides\": {\n",
"4. In the JSON file that opens, add the following lines to the existing dictionary:\n",
"\n",
" ```json\n",
" \"python.analysis.diagnosticSeverityOverrides\": {\n",
" \"reportGeneralTypeIssues\": \"none\",\n",
" \"reportOptionalMemberAccess\": \"none\",\n",
" \"reportWildcardImportFromLibrary\": \"none\",\n",
" \"reportRedeclaration\": \"none\",\n",
" \"reportAttributeAccessIssue\": \"none\",\n",
" \"reportInvalidTypeForm\": \"none\",\n",
" \"reportAssignmentType\": \"none\",\n",
" }\n",
"}\n",
"```\n",
" \"reportAssignmentType\": \"none\"\n",
" }\n",
" ```\n",
"5. Save the file\n",
"\n",
"Even with PyLance diagnostics turned off, your FastHTML code will still run correctly. If you're still seeing some false errors from PyLance, you can disable it entirely by adding this to your settings:\n",
"Even with Pylance diagnostics turned off, your FastHTML code will still run correctly. If you're still seeing some false errors from Pylance, you can disable it entirely by adding this to your settings:\n",
"\n",
"```json\n",
"{\n",
" \"python.analysis.ignore\": [ \"*\" ]\n",
"}\n",
"\"python.analysis.ignore\": [\"*\"]\n",
"```"
]
},
Expand Down Expand Up @@ -139,29 +136,11 @@
"source": [
"Some people are under the impression that writing software in notebooks is bad.\n",
"\n",
"[Watch this video](https://www.youtube.com/watch?v=9Q6sLbz37gk&ab_channel=JeremyHoward). We've used Jupyter notebooks exported via `nbdev` to write a wide range of “very serious” software projects over the last three years. This includes deep learning libraries, API clients, Python language extensions, terminal user interfaces, web frameworks, and more!\n",
"[Watch this video](https://www.youtube.com/watch?v=9Q6sLbz37gk&ab_channel=JeremyHoward). We've used Jupyter notebooks exported via `nbdev` to write a wide range of “very serious” software projects over many years. This includes deep learning libraries, API clients, Python language extensions, terminal user interfaces, web frameworks, and more!\n",
"\n",
"[nbdev](https://nbdev.fast.ai/) is a Jupyter-powered tool for writing software. Traditional programming environments throw away the result of your exploration in REPLs or notebooks. `nbdev` makes exploration an integral part of your workflow, all while promoting software engineering best practices."
]
},
{
"cell_type": "markdown",
"id": "9ad687c4",
"metadata": {},
"source": [
"## Why not pyproject.toml for packaging?"
]
},
{
"cell_type": "markdown",
"id": "d5f9d9d3",
"metadata": {},
"source": [
"FastHTML uses a `setup.py` module instead of a `pyproject.toml` file to configure itself for installation. The reason for this is `pyproject.toml` is not compatible with [nbdev](https://nbdev.fast.ai/), which is what is used to write and build FastHTML.\n",
"\n",
"The nbdev project spent around a year trying to move to pyproject.toml but there was insufficient functionality in the toml-based approach to complete the transition."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
2 changes: 1 addition & 1 deletion nbs/explains/routes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"id": "fc76abcd",
"metadata": {},
"source": [
"TestClient uses `httpx` behind the scenes, so it returns a `httpx.Response`, which has a `text` attribute with our response body:"
"TestClient uses `httpx2` behind the scenes, so it returns an `httpx2.Response`, which has a `text` attribute with our response body:"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions nbs/llms-ctx-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5123,7 +5123,7 @@ tutorial we’ll be using Railway. To get started, make sure you create an
CLI](https://docs.railway.app/guides/cli). Once installed, make sure to
run `railway login` to log in to your account.

To make deploying your website as easy as possible, FastHTMl comes with
To make deploying your website as easy as possible, FastHTML comes with
a built in CLI tool that will handle most of the deployment process for
you. To deploy your website, run the following command in your terminal
in the root directory of your project:
Expand Down Expand Up @@ -9691,7 +9691,7 @@ tags, which are both placed in the head.

[`APIRouter`](https://www.fastht.ml/docs/api/core.html#apirouter) is
useful when you want to split your application routes across multiple
`.py` files that are part of a single FastHTMl application. It accepts
`.py` files that are part of a single FastHTML application. It accepts
an optional `prefix` argument that will be applied to all routes within
that instance of
[`APIRouter`](https://www.fastht.ml/docs/api/core.html#apirouter).
Expand Down
4 changes: 2 additions & 2 deletions nbs/ref/handlers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"id": "42c18142",
"metadata": {},
"source": [
"The `get` method on a `Client` instance simulates GET requests to the app. It returns a response object that has a `.text` attribute, which you can use to access the body of the response. It calls `httpx.get` internally -- all httpx HTTP verbs are supported."
"The `get` method on a `Client` instance simulates GET requests to the app. It returns a response object that has a `.text` attribute, which you can use to access the body of the response. It calls `httpx2.get` internally -- all httpx2 HTTP verbs are supported."
]
},
{
Expand Down Expand Up @@ -1310,7 +1310,7 @@
"id": "f8138c07",
"metadata": {},
"source": [
"`APIRouter` is useful when you want to split your application routes across multiple `.py` files that are part of a single FastHTMl application. It accepts an optional `prefix` argument that will be applied to all routes within that instance of `APIRouter`.\n",
"`APIRouter` is useful when you want to split your application routes across multiple `.py` files that are part of a single FastHTML application. It accepts an optional `prefix` argument that will be applied to all routes within that instance of `APIRouter`.\n",
"\n",
"Below we define several hypothetical product related routes in a `products.py` and then demonstrate how they can seamlessly be incorporated into a FastHTML app instance."
]
Expand Down
6 changes: 3 additions & 3 deletions nbs/tutorials/e2e.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"1. Room Creation and Storage\n",
"\n",
"```{.python filename=\"main.py\"}\n",
"db = database('data/drawapp.db')\n",
"from fastlite import *\ndb = database('data/drawapp.db')\n",
"rooms = db.t.rooms\n",
"if rooms not in db.t:\n",
" rooms.create(id=int, name=str, created_at=str, pk='id')\n",
Expand Down Expand Up @@ -476,14 +476,14 @@
"source": [
"You can deploy your website to a number of hosting providers, for this tutorial we'll be using Railway. To get started, make sure you create an [account](https://railway.app/) and install the [Railway CLI](https://docs.railway.app/guides/cli). Once installed, make sure to run `railway login` to log in to your account.\n",
"\n",
"To make deploying your website as easy as possible, FastHTMl comes with a built in CLI tool that will handle most of the deployment process for you. To deploy your website, run the following command in your terminal in the root directory of your project:\n",
"To make deploying your website as easy as possible, FastHTML comes with a built in CLI tool that will handle most of the deployment process for you. To deploy your website, run the following command in your terminal in the root directory of your project:\n",
"\n",
"```sh\n",
"fh_railway_deploy quickdraw\n",
"```\n",
"\n",
"::: {.callout-note}\n",
"Your app must be located in a `main.py` file for this to work.\n",
"Your app must be located in a `main.py` file for this to work. If `requirements.txt` is missing, this command creates one that lists only `python-fasthtml`. This app also needs `fastlite`, so add that line before you deploy.\n",
":::"
]
},
Expand Down
4 changes: 1 addition & 3 deletions nbs/tutorials/jupyter_and_fasthtml.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
"id": "4b1ee344",
"metadata": {},
"source": [
"Writing FastHTML applications in Jupyter notebooks requires a slightly different process than normal Python applications. \n",
"\n",
":::{.callout-tip title='Download this notebook and try it yourself'}\n",
"The source code for this page is a [Jupyter notebook](https://github.com/AnswerDotAI/fasthtml/blob/main/nbs/tutorials/jupyter_and_fasthtml.ipynb). That makes it easy to directly experiment with it. However, as this is working code that means we have to comment out a few things in order for the documentation to build.\n",
":::\n",
Expand Down Expand Up @@ -168,7 +166,7 @@
"id": "4cb6bb90",
"metadata": {},
"source": [
"You can view your app outside of Jupyter by going to `localhost:PORT`, where `PORT` is usually the default 8000, so in most cases just click [this link](localhost:8000/)."
"You can view your app outside of Jupyter by going to `localhost:PORT`, where `PORT` is usually the default 8000, so in most cases just click [this link](http://localhost:8000/)."
]
},
{
Expand Down
Loading