Interview Prep/Build Tools (Java, Node.js, Python, .NET)/Python builds (pip, venv, requirements.txt)
How do you run a Flask application in development and in production?
BeginnerHands-onPython builds (pip, venv, requirements.txt)
Answer
Short answer
In development use Flask's built-in server (flask run), which auto-reloads but handles one request at a time. In production run it with a WSGI server like gunicorn with several workers, usually behind Nginx or a load balancer.
Example app
# app.py
from flask import Flask
app = Flask(__name__)
@app.get("/health")
def health():
return {"status": "ok"}
Development
flask --app app run --debug --port 5000
Production
gunicorn --workers 4 --bind 0.0.0.0:8000 --timeout 60 --access-logfile - app:app
app:app= fileapp.py, objectapp.--access-logfile -sends access logs to stdout (good for Docker/Kubernetes).
Never in production
debug=True exposes an interactive debugger that can run code on your server.
What to say in the interview
"flask run is development only — single-threaded with optional debug mode. In production we run gunicorn with multiple workers bound to 0.0.0.0, logs to stdout, behind Nginx or an Ingress."
All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Python apps: pip, venv & requirements.txt
More on Python builds (pip, venv, requirements.txt)
How do you install dependencies and run a Python application?BeginnerWhat is a Python virtual environment and why do we need it?BeginnerWhat is requirements.txt and how do you pin versions?BeginnerWhat is gunicorn and how many workers should you run?BeginnerWhat is the difference between WSGI and ASGI?IntermediateHow do you run a FastAPI application?Beginner