Menu

Flask: Complete Definition and Guide

5 min read Mis à jour le 05 Apr 2026

Définition

Flask is a Python web micro-framework created by Armin Ronacher in 2010. Unlike Django, Flask takes a minimalist approach: it provides the bare essentials (routing, templates, request handling) and gives developers the freedom to choose their own tools for everything else.

What is Flask?

Flask is a Python web micro-framework distinguished by its lightweight nature and flexibility. Created in 2010 by Armin Ronacher as part of the Pallets project, Flask was born from an April Fool's joke that turned into a serious project. The term "micro" doesn't mean Flask is limited in features, but rather that it keeps a simple, extensible core. Flask makes no assumptions about the database, template system (though it integrates Jinja2 by default), or authentication layer you'll use.

Flask is built on two fundamental Pallets project libraries: Werkzeug, a WSGI library that handles HTTP requests and responses, and Jinja2, a powerful and secure template engine. From these foundations, developers build their application by adding only the extensions they need.

At KERN-IT, Flask holds a complementary position to Django in our technical stack. We primarily use it for microservices, lightweight APIs, rapid prototypes, and specialized services where Flask's flexibility represents an advantage over Django's more rigid structure.

Why Flask matters

In the Python ecosystem, Flask represents a different development philosophy from Django. This difference is not a flaw: it's an asset that makes it indispensable in certain contexts.

  • Lightweight: a minimal Flask application fits in just a few lines of code. This simplicity reduces project startup time and the learning curve for developers.
  • Total flexibility: Flask imposes no project structure, no ORM, no authentication system. Developers choose exactly the components they need, avoiding the overhead of unused features.
  • Ideal for microservices: in a microservices architecture, each service must be lightweight and independent. Flask is perfectly suited to this paradigm, enabling the creation of specialized services with a minimal footprint.
  • Rapid prototyping: when you need to validate an idea quickly, Flask allows creating a functional POC in a few hours, without the initial configuration required by a full-stack framework.
  • Extension ecosystem: Flask-SQLAlchemy, Flask-Login, Flask-RESTful, Flask-Migrate, and dozens of other extensions allow adding features on demand, transforming Flask into a full-stack framework if necessary.

How it works

Flask's operation is based on the concept of routes and Python decorators. A route associates a URL with a Python function (called a "view function") via a @app.route() decorator. When an HTTP request arrives, Flask uses Werkzeug to parse the URL and match it to the correct view.

Flask uses an application context and request context system that allows accessing current request data (parameters, headers, cookies) via thread-safe global objects. This elegant mechanism avoids passing the request object as a parameter to every function.

The integrated Jinja2 template engine offers a powerful template language with template inheritance, custom filters, macros, and automatic data escaping to prevent XSS attacks. Templates can be organized hierarchically with a base template and child templates that extend or override specific blocks.

For database management, Flask doesn't provide a native ORM but integrates perfectly with SQLAlchemy via the Flask-SQLAlchemy extension. This approach allows developers to choose between SQLAlchemy for projects requiring a full ORM, or to directly use a database library for simple cases.

Real-world example

KERN-IT uses Flask in several operational contexts. A common use case is developing specialized microservices within a larger architecture. For example, for a large-scale web scraping project, we developed a dedicated Flask service that exposes a RESTAPI for submitting scraping tasks, monitoring their progress, and retrieving results. This service operates independently from the main Django backend, communicating via Redis and webhooks.

Another concrete example is using Flask for artificial intelligence services. Consider a company that needs to expose a machine learning model via an API. A Flask microservice can encapsulate the trained model, expose a prediction endpoint, and manage model versioning. This decoupled architecture allows updating the ML model independently from the rest of the application, facilitating iterations and continuous deployment.

Flask is also our choice for internal tools and administration scripts exposed via a web interface. A monitoring dashboard with a few endpoints doesn't justify setting up a complete Django project: Flask allows creating this tool in a few hours with minimal code.

Implementation

  1. Installation: install Flask in a virtual environment with pip install flask. Create an app.py file with a minimal application to verify everything works.
  2. Project structure: for medium-sized projects, adopt the "application factory" structure with a Python package, an __init__.py file containing the create_app() factory, and blueprints to organize routes by functional domain.
  3. Configuration: use configuration classes to separate development, test, and production settings. Load secrets from environment variables with os.environ or python-dotenv.
  4. Extensions: add necessary extensions: Flask-SQLAlchemy for the database, Flask-Migrate for Alembic migrations, Flask-Login for authentication, Flask-CORS for cross-origin requests.
  5. Testing: use Flask's built-in test client with pytest. Test each endpoint with simulated requests and verify status codes and response data.
  6. Deployment: never use Flask's development server in production. Deploy with Gunicorn or uWSGI behind Nginx, in a Docker container for portability.

Associated technologies and tools

  • Python: the foundational language on which Flask is built.
  • SQLAlchemy: the reference Python ORM, used with Flask via Flask-SQLAlchemy.
  • Jinja2: template engine integrated into Flask, also used by Django and Ansible.
  • Celery: asynchronous task manager, usable with Flask for background processing.
  • Docker: containerization of Flask microservices for isolated and reproducible deployment.
  • Redis: used as cache and message broker in Flask microservice architectures.
  • FastAPI: modern alternative to Flask for performant APIs with automatic data validation.
  • Gunicorn: WSGI server for deploying Flask in production.

Conclusion

Flask is the ideal companion to Django in a comprehensive Python development strategy. Where Django excels for complex web applications and full-stack platforms, Flask shines for microservices, lightweight APIs, and rapid prototypes. At KERN-IT, we use both frameworks in a complementary manner, choosing the tool best suited to each context. Our mastery of Flask, combined with our Django expertise, allows us to offer our clients flexible and performant software architectures capable of adapting to the most varied needs.

Conseil Pro

Systematically use the "application factory" pattern with create_app() from the start of your Flask project, even for small projects. This pattern facilitates testing, per-environment configuration, and future application evolution.

Un projet en tête ?

Discutons de comment nous pouvons vous aider à concrétiser vos idées.