diff --git a/doc/how_to/integrations/FastAPI.md b/doc/how_to/integrations/FastAPI.md index fec10d37d2..a03ad1e230 100644 --- a/doc/how_to/integrations/FastAPI.md +++ b/doc/how_to/integrations/FastAPI.md @@ -2,32 +2,26 @@ Panel generally runs on the Bokeh server, which itself runs on [Tornado](https://tornadoweb.org/en/stable/). However, it is also often useful to embed a Panel app in an existing web application, such as a [FastAPI](https://fastapi.tiangolo.com/) web server. -Since Panel 1.5.0 it is possible to run Panel application(s) natively on a FastAPI and uvicorn based server. Therefore this how-to guide will explain how to add Panel application(s) directly to an existing FastAPI application. This functionality is new and experimental so we also provide a [how-to guide to embed a Tornado based Panel server application inside a FastAPI application](./FastAPI_Tornado). +Since Panel 1.5.0 it is possible to run Panel application(s) natively on a FastAPI and uvicorn based server via . Therefore this how-to guide will explain how to add Panel application(s) directly to an existing FastAPI application. This functionality is new and experimental so we also provide a [how-to guide to embed a Tornado based Panel server application inside a FastAPI application](./FastAPI_Tornado). By the end of this guide, you'll be able to run a FastAPI application that serves a simple interactive Panel app. The Panel app will consist of a slider widget that dynamically updates a string of stars (⭐) based on the slider's value. ## Setup -Following FastAPI's [Tutorial - User Guide](https://fastapi.tiangolo.com/tutorial/) make sure you first have FastAPI installed using: +Following FastAPI's [Tutorial - User Guide](https://fastapi.tiangolo.com/tutorial/) make sure you first have [FastAPI](https://fastapi.tiangolo.com/) and [bokeh-fastapi] installed using: ::::{tab-set} -:::{tab-item} `conda` -```bash -conda install fastapi -``` -::: - :::{tab-item} `pip` ```bash -pip install fastapi +pip install panel[fastapi] ``` ::: -:::{tab-item} `panel` -```bash -pip install panel[fastapi] -``` +:::{tab-item} `conda` + +Currently not supported + ::: :::: @@ -92,7 +86,7 @@ fastapi dev main.py You should see the following output: -``` +```bash INFO Using path main.py INFO Resolved absolute path /home/user/code/awesomeapp/main.py INFO Searching for package file structure from directories with __init__.py files @@ -165,6 +159,16 @@ add_applications({ }, app=app) ``` +## Tips & Tricks + +### Running Behind a Proxy + +In some cases, you might be running your FastAPI app behind a reverse proxy, which adds an extra path prefix that your application doesn't directly handle. This is common when working in environments like JupyterHub or deploying to Kubernetes. + +For instance, if your FastAPI `/` endpoint is accessed at `https://some.domain/some/path/`, you will need to specify the path prefix when starting your FastAPI server. To do this, use the flag `--root-path /some/path/`. This ensures you can access the OpenAPI docs at `https://some.domain/some/path/docs`. + +For more details, refer to the [Behind a Proxy](https://fastapi.tiangolo.com/advanced/behind-a-proxy/) guide. + ## Conclusion That's it! You now have embedded panel in FastAPI! You can now build off of this to create your own web app tailored to your needs. diff --git a/pyproject.toml b/pyproject.toml index 6e1fd344cf..2bcd8dce9f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,8 +77,8 @@ recommended = [ 'plotly', ] fastapi = [ - 'bokeh-fastapi == 0.1.0', - 'uvicorn', + 'bokeh-fastapi >= 0.1.0', + 'fastapi[standard]', ] dev = [ 'watchfiles',