This guide shows how to install and run a basic Flask application. Flask is a Python framework that can be used to create Web and API application.





01. Activate your virtual environment, or skip this step if not using virtual environment.

$ source {{virtual-env-directory}}/bin/activate


02. Install the Flask package

(geek-venv) $ pip install -U Flask


03. Verify the Flask has been installed by creating a sample application

(geek-venv) $ nano geek_flask_api.py


Set the content as follows

from flask import Flask
from flask import jsonify
application = Flask(__name__)

@application.route(“/”, methods=['GET'])
def root_path():
  app_properties = \
    ‘name’ : ‘geek-flask-api’
    , ‘version’ : ‘1.0.0.’
  return jsonify(app_properties)


04. Run the application

(geek-venv) $ env FLASK_APP=geek_flask_api.py flask run


05. Open a CLI window and use cURL to view the response of the application. In this example


Press Ctrl+C to terminate the application.


06. Congratulations! Flask has been installed

Previous How To Call Azure REST APIs
Next How To Install Django