0

What is the best option to run a Python Flask rest api service on a windows machine? Not on Azure

I have tried multiple options using fastcgi and httphandler and a windows service.

I want to know what other use to host a Python Flask rest api on a windows server in a production environment

1 Answer 1

2

If you want to just "run" a flask app on windows, then all you need is python. Install flask and you are good to go:

pip install flask

Once you have flask, you can write any script using it and just call it using python:

# hello_world.py
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

flask is WSGI compatible, so you can host this script locally by running python hello_world.py on the DOS prompt.

But if you talking about production hosting on a windows machine instead of linux, then I don't think its a good idea. Most popular options for WSGI hosting like uwsgi and gunicorn are linux only (unless you perform hackish workarounds like cygwin).

Sign up to request clarification or add additional context in comments.

4 Comments

So you would not recommend hosting a python service on windows? You are right the only options i have seen for windows deployment are hackish. that's why i reached out to see what other were doing.
@shivas Yes, you can install cygwin and in theory use gunicorn or uwsgi on top of that, but its performance and stability needs to be seen as those components are never built for windows platform. The only windows option that flask deployment guide recommends is the Azure/IIS based.
If I run the code in your answer using python hello_world.py, can I see the app in my browser? On which port would I find?
Its usually port 5000, but might differ based on your configuration. When you run the script from a command prompt using python, it'll usually print the port number information like this: Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.