Skip to content

mariuszdotnet/python-fast-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python FastAPI on Azure Web Apps (Linux)

Live Demo API running on Azure.

To run the application locally:

  1. Go to the application folder:

    cd python-fast-api
  2. Create a virtual environment for the app:

    python3 -m venv .venv
    source .venv/bin/activate
  3. Install the dependencies as per the documentation:

    pip install fastapi
    pip install uvicorn[standard]
  4. Generate the requirements.txt file for Azure deployment.

    pip freeze > requirements.txt
  5. Test install the dependencies with the requirements.txt file. (OPTIONAL)

    pip install -r requirements.txt
  6. Run the app:

    uvicorn main:app --reload

To run the application on Azure App Service:

  1. In the Azure Web App under Settings -> Configuration -> Application settings make sure the application setting SCM_DO_BUILD_DURING_DEPLOYMENT is defined and set to 1. This instructs the build of the webapp container to install the requirements.txt dependencies for your application.

  2. 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 more

    gunicorn -k uvicorn.workers.UvicornWorker main:app

Note:

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 Appsas described here.

References:

About

Python FastAPI Example

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages