Flask Web Service


This article will show you very quickly how to use Python as a web server using the 3rd party Flask framework.

Flask is a very easy to use web application framework for writing web servers with Python. It's much easier and offers more features than the native HTTPServer module in Python. It's highly recommended if you plan on writing back end web services or hosting web sites with Python.

You can see how much easier this is compared with the article 'HTTP Web Service'.

The Code

from flask import Flask

app = Flask(__name__)

def index():
    return 'Hello from flask!''localhost', port=81)

When you run, you will see in the terminal the server running message. While the server is running, open your browser and browse to "http://localhost:81".

You should see a response in your browser that came from your server on line 7.

Next Steps

Explore the Flask framework over at I suggest going through the "Quickstart" sections to see what Flask can offer you.