Flask is a lightweight Python web framework often described as a "micro-framework" — it gives you routing and request handling out of the box, and lets you add only the extra pieces you need.
What is Flask?
Flask maps URLs to Python functions. When a browser requests a URL, Flask finds the matching function ("view") and returns whatever it produces — usually HTML or JSON.
Installing Flask
pip install flask
Your First App
Create a file named app.py with the following contents:
from flask import Flask
app = Flask(__name__)
# @app.route maps a URL path to a Python function
@app.route("/")
def home():
return "Hello, DevQura!"
Adding Routes
Routes are defined with the @app.route() decorator. You can accept different HTTP methods and read data from the request:
@app.route("/greet/<name>")
def greet(name):
return f"Hello, {name}!"
@app.route("/api/status", methods=["GET"])
def status():
return {"status": "ok"}
Flask automatically converts a returned Python dictionary into a JSON response — no extra imports needed.
Running the Server
python app.py
Visit http://127.0.0.1:5000 in your browser to see the response. Flask's debug mode automatically reloads the server when you save changes.