Live Demo API running on Azure.
-
Go to the application folder:
cd python-fast-api
-
Create a virtual environment for the app:
python3 -m venv .venv source .venv/bin/activate
-
Install the dependencies as per the documentation:
pip install fastapi pip install uvicorn[standard]
-
Generate the requirements.txt file for Azure deployment.
pip freeze > requirements.txt
-
Test install the dependencies with the requirements.txt file. (OPTIONAL)
pip install -r requirements.txt
-
Run the app:
uvicorn main:app --reload
-
In the Azure Web App under
Settings
->Configuration
->Application settings
make sure the application settingSCM_DO_BUILD_DURING_DEPLOYMENT
is defined and set to1
. This instructs the build of the webapp container to install therequirements.txt
dependencies for your application. -
In the Azure Web App under
Settings
->Configuration
->Application settings
->Startup Command
orovide an optional startup command that will be run as part of container startup. learn moregunicorn -k uvicorn.workers.UvicornWorker main:app
uvicorn.workers.UvicornWorker
is an ASGI worker class for Gunicorn that wraps the uvicorn server. It is used to run ASGI applications with Gunicorn. The Azure App Serice image for Linux with Python runtime runs Gunicorn by default.
You can build your own custom image to run Fast API on Azure Web Apps
as described here.
You can build your own custom image to run FastAPI on Azure Container Apps
as described here.