Gunicorn is a widely used WSGI server for running Python web applications. When deploying FastAPI, Gunicorn is often used in conjunction with Uvicorn to provide a production-ready server.
Install Gunicorn using:
pip install gunicorn
Run Gunicorn with Uvicorn workers:
gunicorn -k uvicorn.workers.UvicornWorker your_app:app -w 4 -b 0.0.0.0:8000
Here:
-k uvicorn.workers.UvicornWorkerspecifies the worker class.your_app:apppoints to your FastAPI application instance.-w 4sets the number of worker processes. Adjust this based on the available resources and expected load.