Flask + PostgreSQL

Flask microframework with PostgreSQL, usually through Flask-SQLAlchemy and Flask-Migrate, a long-standing lightweight Python stack for small web apps, internal tools and APIs.

  • FlaskFlask
  • PythonPython
  • PostgreSQLPostgreSQL
Learning curve
Easy
Status
Mature and maintained
Reviewed
November 2026
Best for
  • Small to medium server-rendered apps and internal dashboards
  • Wrapping an existing Python library or model behind a few HTTP endpoints
  • Teams that want to pick each component instead of following a framework
  • Prototypes and teaching, where every line of the app is visible
Not ideal for
  • High-concurrency async or WebSocket API
  • Large multi-team product monolith

Overview

Flask gives you routing, a request context, Jinja2 templates and little else; PostgreSQL is usually reached through Flask-SQLAlchemy with Flask-Migrate (Alembic) for schema changes, or psycopg directly for small apps. Everything else, from auth to validation to API docs, is an extension you choose. Teams reach for it when they want a small, readable Python web app or API without Django's conventions or FastAPI's async model.

What's inside

The core fits in an afternoon. The real learning is choosing and wiring extensions, understanding app and request contexts, and imposing a project structure that will scale with the team.

  • Flask

    Flask

    Backend

    Handles requests, business logic and APIs

    Learning: Easy

    Status: Mature

  • PostgreSQL

    PostgreSQL

    Database

    Stores and queries the data

    Learning: Moderate

    Status: Active

  • Python

    Python

    Language

    The language the code is written in

    Learning: Easy

    Status: Active

How it works

A WSGI server such as Gunicorn runs Flask worker processes; each request gets an application and request context, a view function queries PostgreSQL through a request-scoped SQLAlchemy session, and returns a Jinja2 page or JSON.

  1. 1.

    Infrastructure to backend

    Nginx or a platform router forwards the request to a Gunicorn worker, which pushes Flask's app and request contexts and runs before_request hooks.

  2. 2.

    Backend to database

    The view function, registered on a blueprint, queries PostgreSQL through Flask-SQLAlchemy's scoped session (db.session) or a psycopg connection from a pool.

  3. 3.

    Database to backend

    Rows come back as model objects or tuples; the view renders a Jinja2 template or serialises JSON, typically via marshmallow or a hand-written dict.

  4. 4.

    Backend to infrastructure

    Teardown handlers commit or roll back and remove the session, returning the connection to the pool before the response is sent.

Strengths and drawbacks

Strengths

  • Small, explicit core

    A working app is a few lines, there is no hidden project layout, and routing, request handling and templating are easy to read and debug with Werkzeug's debugger.

  • Very stable API

    Flask's core API has changed little over many years, so tutorials, extensions and existing apps stay valid and upgrades are usually small.

  • Mature PostgreSQL path

    Flask-SQLAlchemy and Flask-Migrate give the full SQLAlchemy ORM, Alembic migrations and PostgreSQL types such as JSONB and arrays without extra glue.

  • Blueprints and app factories

    Blueprints split routes into modules and the create_app factory pattern makes separate configs for tests, staging and production straightforward.

Drawbacks

  • Structure is your job

    Flask does not decide where services, validation or auth live. Without early conventions, apps drift into large views.py files with globals, circular imports and inconsistent error handling.

  • Synchronous WSGI model

    Async views are supported but each request still occupies a worker thread, so Flask gains little from async I/O. High-concurrency or WebSocket-heavy services fit FastAPI or Quart better.

  • No built-in validation or API docs

    Request validation and OpenAPI need extensions such as marshmallow, flask-smorest or APIFlask; FastAPI gives both from type hints out of the box.

  • Uneven extension maintenance

    Extensions are community-run and maintenance varies; some that still appear in tutorials have stalled, so check release activity before depending on one for auth or admin.

  • Context locals surprise newcomers

    request, g and current_app are context-bound proxies, which causes 'working outside of application context' errors in scripts, background threads and tests until the pattern is understood.

Scores

Editorial ratings out of 10, comparable across every stack in the guide. They are judgement, not benchmarks. How we score

Speed of building
7.2 out of 10, catalog average 7.7

How quickly a team ships features

Ease of learning
8.6 out of 10, catalog average 7.2

Higher means easier to pick up

Scalability
6.8 out of 10, catalog average 7.6

How far it grows before a redesign

Performance
6.0 out of 10, catalog average 7.5

Speed of the running application

Maintainability
6.0 out of 10, catalog average 7.2

How well the codebase ages

Ecosystem
8.2 out of 10, catalog average 8.2

Libraries, hosting, docs and hiring

Flexibility
8.4 out of 10, catalog average 7.4

How many kinds of product it suits

How it scales

Stateless Gunicorn workers scale horizontally; per-process memory and synchronous request handling mean you add processes rather than concurrency, with PostgreSQL connections as the main shared limit.

Starting outMVP and first users
One VM or PaaS dyno running Gunicorn with a few sync workers and a small managed PostgreSQL instance.
GrowingReal traffic, a few engineers
Several Gunicorn containers behind a load balancer, gthread or gevent workers for I/O-heavy endpoints, PgBouncer, and Redis for sessions and caching.
LargeHeavy traffic or data
Autoscaled containers with a separate job queue (Celery or RQ), PostgreSQL read replicas for heavy reads, and CDN caching for static and public pages.
EnterpriseMany teams and regions
Typically split into several Flask or FastAPI services with their own databases; few organisations keep a single very large Flask monolith at this scale.

Where it fits

Common projects, from best fit to worst.

  • Internal tool or ops dashboard

    A few Jinja2 pages over PostgreSQL tables with simple login ship quickly and stay easy for any Python developer to modify.

    Great fit

  • HTTP wrapper for a Python library or model

    Exposes an existing scoring function or data job as a small synchronous API without framework overhead.

    Good fit

  • Large multi-team product monolith

    Possible with strict conventions, but teams end up rebuilding the structure, auth and admin that Django or Rails provide.

    Workable

  • High-concurrency async or WebSocket API

    WSGI workers hold a thread per request, so thousands of long-lived connections are cheaper on FastAPI, Quart, Node.js or Go.

    Poor fit

Alternatives

Similar stacks, and when you would choose them instead.

Sources

Reviewed on November 19, 2026 against the documentation below. Found something out of date? Suggest a correction. Read our methodology.

Stacks that share technologies with Flask + PostgreSQL.