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.
- Flask
- Python
- PostgreSQL
- 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
Backend
Handles requests, business logic and APIs
Learning: Easy
Status: Mature
PostgreSQL
Database
Stores and queries the data
Learning: Moderate
Status: Active
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.
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.
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.
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.
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
- Ease of learning
- 8.6 out of 10, catalog average 7.2
- Scalability
- 6.8 out of 10, catalog average 7.6
- Performance
- 6.0 out of 10, catalog average 7.5
- Maintainability
- 6.0 out of 10, catalog average 7.2
- Ecosystem
- 8.2 out of 10, catalog average 8.2
- Flexibility
- 8.4 out of 10, catalog average 7.4
How quickly a team ships features
Higher means easier to pick up
How far it grows before a redesign
Speed of the running application
How well the codebase ages
Libraries, hosting, docs and hiring
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.
- Django + PostgreSQL
Pick Django when the app needs auth, an admin UI, forms and migrations from day one and you would rather follow conventions than assemble extensions.
CompareFlask + PostgreSQL with Django + PostgreSQL - FastAPI + SQLAlchemy + PostgreSQL
Pick FastAPI with SQLAlchemy for JSON APIs that need async I/O, request validation and generated OpenAPI docs, using the same ORM.
CompareFlask + PostgreSQL with FastAPI + SQLAlchemy + PostgreSQL - Express + PostgreSQL
The minimalist Node.js equivalent, for teams standardised on JavaScript or TypeScript across frontend and backend.
CompareFlask + PostgreSQL with Express + PostgreSQL
Sources
Reviewed on November 19, 2026 against the documentation below. Found something out of date? Suggest a correction. Read our methodology.
- Flask documentation
Official Flask docs, including application factories and blueprints.
- Flask: Using async and await
Explains why async views in Flask still run per request in a worker thread.
- Flask: Deploying to Production
Official guidance on WSGI servers such as Gunicorn.
- Flask-SQLAlchemy documentation
The usual ORM integration for Flask + PostgreSQL apps.
Related stacks
Stacks that share technologies with Flask + PostgreSQL.
FastAPI + PostgreSQL
FastAPI API services with PostgreSQL, a high-adoption Python API stack for microservices and ML-adjacent backends.
- FastAPI
- Python
- PostgreSQL
- +1
Learning: Easy
Django + Celery + Redis + PostgreSQL
Django web app with Celery workers, Redis as broker and cache, and PostgreSQL as the system of record, the standard way to move slow work out of Django requests.
- Django
- Celery
- Redis
- +2
Learning: Moderate
Airflow + PostgreSQL
Apache Airflow orchestrating Python-defined DAGs, with PostgreSQL as the metadata database, the standard self-hosted Airflow production setup.
- Apache Airflow
- Python
- PostgreSQL
Learning: Hard