What is Gunicorn ?
Gunicorn, a WSGI server, can be used alongside Uvicorn to serve FastAPI applications, despite not being specifically designed for ASGI. Commonly paired with frameworks like Flask and Django, Gunicorn boasts a mature ecosystem and is favored for production deployments. However, its synchronous nature, processing one request at a time per worker process, necessitates combining it with Uvicorn for optimal utilization of asynchronous programming in FastAPI.
Example:
Python3
import uvicorn from fastapi import FastAPI app = FastAPI() @app .get( "/" ) async def index(): return { "message" : "Hello World" } |
run the below command
gunicorn main:app --reload --log-level info --workers 3 --bind 0.0.0.0:8000
Output:
Note: Gunicorn works in docker or linux os systems, in windows it might not work.
Message: Hello World!!!!