Running an ASGI Python Web Application in Azure with Gunicorn and Uvicorn

Published on

Heads up! This information might be outdated since it was last updated over a year ago. Please double-check the information before relying on it.

Assuming you’re using a Linux web application plan, and running a Python application that requires the use of Uvicorn, here are some tips.

You’ll need to have a startup command set in Azure, which either calls a Uvicorn worker directly, or calls a configuration file specifying one.

On the Azure Portal, open your Web App, scroll to ‘Configuration’ under ‘Settings’, click on the ‘General Settings’ tab, and enter the appropriate startup command.gunicorn -c gunicorn_config.py app:app TODO: Add caption Once your startup command is set, you’ll also need to have a gunicorn_config.py file in your web app deployment.

# Configuration for Gunicorn on Azure
# Azure Startup Command should be: gunicorn -c gunicorn_config.py app:app
# See: https://docs.gunicorn.org/en/stable/settings.html#config
workers = 4
worker_class = "uvicorn.workers.UvicornWorker"

Finally, in your requirements.txt file, you’ll need to specify additional dependencies:

# Required for deploying to Azure
uvicorn
uvloop
httptools