Home > Enterprise >  Python serverless webapp vs WSGI server
Python serverless webapp vs WSGI server

Time:12-08

I'm developing a web application with Python Flask.

I read something about WSGI server and the warning message "WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead."

If I'm using GKE or App Engine or Cloud Ran, is WSGI something I need to learn?

CodePudding user response:

TLDR: No, you don't. You just need to know how to run your App with Flask. Having said that, it doesn't mean that learning/understanding WSGI is a waste but it isn't required.

Longer response

Gunicorn is a Production WSGI Webserver and this is what Google uses on their Production server to run your Apps for Google App Engine (if your App doesn't contain an entrypoint). Waitress is another Production WSGI webserver.

You don't necessarily have to 'learn' how to use any of them or the intricacies of WSGI to be able to build an App. Learning and understanding how Flask works is good enough

  1. For Google App Engine

    Just build and test your App on your dev environment with Flask (e.g. run your app with flask run main.py. When you deploy your App to Google App Engine, it will be run with Gunicorn (unless you specified an entrypoint that doesn't use gunicorn)

    If on the other hand you use dev_appserver.py to run your app locally e.g. you run your app with dev_appserver.py app.yaml, gcloud CLI will first install gunicorn and then use it to run your App on your local machine.

    In both of these instances, you don't have to be an expert on WSGI or gunicorn. Just knowing enough to run your app with Flask is what you need.

    However, note that you can't run Python 3 Apps locally with dev_appserver.py on a Windows machine (see google documentation). I believe it's because gunicorn doesn't run on Windows. But if you still want to use dev_appserver.py for Python 3 Apps on a Windows machine, you can check out a Patch we created (the patch essentially swaps out Gunicorn for Waitress when running your App on your dev machine)

  2. For Cloud Run

    You can code and test your App with Flask and then use gunicorn in the container (you don't necessarily have to be an expert or know a lot about gunicorn). See 'hello world' sample application from Google

  • Related