Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsApr 12, 2026·3 min de lecture

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.

Introduction

Flask is a lightweight WSGI web application framework for Python. Created by Armin Ronacher in 2010 as part of the Pallets project. Flask is called a "micro framework" because it keeps the core simple but extensible — you choose your ORM, template engine, and tools. Trusted by Netflix, LinkedIn, Pinterest, Twilio, and the Python community at large.

What Flask Does

  • Routing — decorator-based URL rules
  • Templates — Jinja2 template engine
  • Request/response — Werkzeug WSGI utilities
  • Blueprints — modular application components
  • Extensions — Flask-SQLAlchemy, Flask-Login, Flask-CORS, Flask-Migrate, Flask-RESTful
  • CLIflask run, custom commands
  • Sessions — cookie-based, configurable
  • Testing — built-in test client
  • Context — application and request context management
  • Signals — Blinker-based event system

Architecture

WSGI application. Request enters Werkzeug server, Flask routes it by matching URL rules (decorated functions). Request context is pushed per-request, providing access to request, g, session globals. Jinja2 renders HTML. Blueprints organize large apps into reusable modules.

Self-Hosting

# Production (never use flask run in prod)
pip install gunicorn
gunicorn app:app --bind 0.0.0.0:8000 --workers 4

# Docker
FROM python:3.12-slim
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["gunicorn", "app:app", "--bind", "0.0.0.0:8000"]

Key Features

  • Minimal core (~1500 lines)
  • Decorator-based routing
  • Jinja2 templates
  • Werkzeug request/response
  • Blueprints for modularity
  • Extensive extension ecosystem
  • Built-in debugger
  • Test client
  • CLI via Click
  • Flask 3.0+ requires Python 3.8+

Comparison

Framework Type Async ORM
Flask Micro WSGI (sync) Via extension
FastAPI Async micro ASGI Via SQLAlchemy
Django Full-stack WSGI + ASGI Built-in
Bottle Micro WSGI None
Litestar Async full ASGI Built-in

FAQ

Q: Flask vs FastAPI? A: FastAPI has native async, built-in OpenAPI docs, and Pydantic validation — good for modern APIs; Flask is simpler with an older ecosystem and more tutorials. For new pure-API projects, FastAPI is recommended; Flask is great for full-stack or existing projects.

Q: Does Flask support async? A: Flask 2.0+ supports async views, but the underlying layer is still WSGI (async runs in a threadpool). For true async I/O, use FastAPI or Quart (Flask's async fork).

Q: How to organize large projects? A: Use Blueprints to split modules by feature. The Application Factory pattern (a create_app() function) supports different environment configurations.

Sources

Discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires