ScriptsApr 12, 2026·3 min read

Flask — The Python Micro Web Framework

Flask is a lightweight WSGI web application framework for Python. Designed to make getting started quick and easy, with the ability to scale up to complex applications. The minimalist counterpart to Django, trusted by Netflix, LinkedIn, and Pinterest.

TL;DR
Flask is a lightweight Python web framework for building APIs and web apps. Quick to start, extensible to complex applications.
§01

What it is

Flask is a lightweight WSGI web application framework for Python. It provides routing, request handling, templating (Jinja2), and session management with minimal overhead. Flask follows a microframework philosophy: include only what you need, add extensions for everything else.

Flask is the minimalist counterpart to Django. Where Django provides an all-in-one solution with ORM, admin, and auth built in, Flask gives you a foundation and lets you choose your own database layer, authentication system, and project structure.

§02

How it saves time or tokens

Flask gets a web server running in under 10 lines of Python. No project scaffolding, no configuration files, no boilerplate. For prototyping, this speed-to-first-request is unmatched.

Flask is one of the most documented Python frameworks. AI coding assistants produce accurate Flask code reliably because the patterns are simple and well-represented in training data.

Additionally, the project's well-structured documentation and active community mean developers spend less time troubleshooting integration issues. When AI coding assistants generate code for this tool, they can reference established patterns from the documentation, producing correct implementations with fewer iterations and lower token costs.

§03

How to use

  1. Install Flask:
pip install flask
  1. Create a minimal application:
from flask import Flask, jsonify, request

app = Flask(__name__)

@app.route('/api/hello')
def hello():
    name = request.args.get('name', 'World')
    return jsonify({'message': f'Hello, {name}'})

if __name__ == '__main__':
    app.run(debug=True)
  1. Add extensions as needed: Flask-SQLAlchemy for database, Flask-Login for authentication, Flask-CORS for cross-origin requests.
  1. Deploy with Gunicorn or uWSGI behind Nginx for production.
§04

Example

from flask import Flask, jsonify, request
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
db = SQLAlchemy(app)

class Task(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(200), nullable=False)
    done = db.Column(db.Boolean, default=False)

@app.route('/api/tasks', methods=['GET'])
def list_tasks():
    tasks = Task.query.all()
    return jsonify([{'id': t.id, 'title': t.title, 'done': t.done} for t in tasks])
§05

Related on TokRepo

§06

Common pitfalls

  • Using Flask's built-in development server in production. Always deploy with Gunicorn or uWSGI. The development server is single-threaded and not designed for production traffic.
  • Not using application factories for larger projects. As Flask apps grow, the factory pattern (create_app function) prevents circular imports and enables testing.
  • Ignoring Flask-Migrate for database schema changes. Without migration tracking, schema changes require manual SQL or database recreation.
  • Failing to review community discussions and changelogs before upgrading. Breaking changes in major versions can disrupt existing workflows. Pin versions in production and test upgrades in staging first.

Frequently Asked Questions

When should I choose Flask over Django?+

Choose Flask when you want full control over your stack, need a lightweight API server, or prefer choosing your own ORM and auth system. Choose Django when you want an all-in-one framework with admin panel, ORM, and auth built in. Flask is better for microservices and APIs; Django is better for full-stack web applications.

Is Flask suitable for production applications?+

Yes. Flask powers production applications at companies including Netflix, LinkedIn, and Pinterest. Deploy with Gunicorn or uWSGI behind Nginx, use a proper database, and add monitoring. Flask itself is production-ready; the development server is not.

How does Flask handle database access?+

Flask does not include a database layer. The most common extension is Flask-SQLAlchemy, which integrates SQLAlchemy ORM with Flask. You can also use raw SQL, PyMongo for MongoDB, or any other Python database library.

Does Flask support async/await?+

Flask 2.0+ supports async route handlers and views. You can use async def for route functions. However, Flask's WSGI foundation means true async performance requires an ASGI server. For heavy async workloads, consider FastAPI or Starlette.

Can Flask build REST APIs?+

Yes. Flask is widely used for REST APIs. Use flask.jsonify for JSON responses, request.get_json() for parsing request bodies, and Flask-RESTful or Flask-Smorest for structured API development with validation and documentation.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets