Flask is Python's premier lightweight, extensible microframework for web development and REST API engineering. Created by Armin Ronacher and the Pallets Projects in 2010, Flask is built upon two battle-tested foundational libraries: Werkzeug (a comprehensive WSGI utility library) and Jinja2 (a fast, sandboxed template engine).
Unlike heavyweight, "batteries-included" monolithic frameworks like Django, Flask adheres to the microframework philosophy: provide a rock-solid, minimal core and let developers choose their own database ORM, authentication provider, form validation library, and serialization layers.
The term "micro" does not mean Flask lacks power, nor does it imply your application must fit in a single file. Rather, "micro" means:
| Dimension | Flask | Django | FastAPI |
|---|---|---|---|
| Framework Category | Microframework | Monolithic "Batteries-Included" | Async Microframework |
| Underlying Standard | WSGI (synchronous core, optional async) | WSGI / ASGI hybrid | ASGI (Native Asynchronous) |
| Default ORM | None (Flask-SQLAlchemy optional) | Django ORM (Built-in, required) | None (SQLAlchemy / Tortoise) |
| Admin Interface | Optional (Flask-Admin) | Built-in Auto-Generated Admin | None |
| Templating | Jinja2 | Django Templates / Jinja2 | Jinja2 (optional) |
| Learning Curve | Extremely low to start; scales cleanly | Steep initially due to monolithic conventions | Moderate (requires Pydantic & Async knowledge) |
| Best Used For | Microservices, REST APIs, custom web apps | Enterprise portals, CMS, rapid admin scaffolding | High-throughput async APIs, real-time AI endpoints |
In Python web development, Python code cannot communicate directly with low-level web servers like Nginx or Apache out of the box. The Web Server Gateway Interface (WSGI) (specified in PEP 3333) standardizes communication between web servers and Python web applications.
+------------------+ HTTP (port 80/443) +----------------------+
| Client Browser | =================================> | Nginx (Web Server) |
+------------------+ +----------------------+
|
WSGI Protocol (Socket)
v
+------------------------------------------------------------------------------+
| Gunicorn / uWSGI (WSGI Server) |
| |
| 1. Parses HTTP byte stream into WSGI 'environ' dictionary. |
| 2. Calls application callable: response = app(environ, start_response) |
+------------------------------------------------------------------------------+
|
v
+------------------------------------------------------------------------------+
| Flask Application (WSGI Callable) |
| |
| 1. Werkzeug wraps 'environ' into a rich 'request' object. |
| 2. Dispatches URL to matching view function. |
| 3. Calls start_response(status, headers). |
| 4. Returns iterable response body bytes (HTML/JSON). |
+------------------------------------------------------------------------------+Every WSGI-compliant Python application is fundamentally a callable function or class that accepts two arguments:
Flask subclasses this concept into an elegant, object-oriented Flask class. When you instantiate app = Flask(__name__), app is a valid WSGI callable that can be directly passed to servers like Gunicorn or Werkzeug!
Werkzeug handles the heavy lifting under Flask's hood:
current_app, g) and request context (request, session), making globals thread-safe.Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| None | Virtual Environments & First Flask Application |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.