Can we build a fastapi application just with nginx + gunicorn as web server and WSGI without using uvicorn?

1k views Asked by At

Can we build a fastapi application just with nginx + gunicorn as web server and WSGI without using uvicorn. Reason why I am asking this is my application has no low level async activities. So I dont need an ASGI (uvicorn). So Can I just exclude using it and proceed with nginx and gunicorn?

1

There are 1 answers

0
Yagiz Degirmenci On BEST ANSWER

So can I just exclude using it and proceed with Nginx and gunicorn?

Short answer: No, you can not.

Slightly longer answer: FastAPI's async functionality is optional, however, FastAPI is based on ASGI specification and built top on an ASGI framework, it is not forcing you to use coroutines in your app however you will need an ASGI HTTP server to run FastAPI.

Why?

ASGI and WSGI are completely different specifications, If your application is based on ASGI specification your application needs 3 fundamental parameters, which we do not have in WSGI.

scope: The connection scope information, a dictionary that contains at least a type key specifying the protocol that is incoming

receive: an awaitable callable that will yield a new event dictionary when one is available

send: an awaitable callable taking a single event dictionary as a positional argument that will return once the send has been completed or the connection has been closed