
SQLAlchemy
Python SQL toolkit and ORM, the standard way Python apps outside Django talk to relational databases.
221 open-source projects declare SQLAlchemy in their code; 1 maker's product we track uses it. What makers like most: Its data-mapper and query-object style makes SQL reusable and composable without hiding the database, from simple selects to multi-join aggregates. Their most common complaint: It feels complicated, and it is hard to see what SQL it actually runs or spot hidden queries in loops.
Profile checked
How makers use SQLAlchemy
Makers' products we track use SQLAlchemy for database access & ORMs (1).
What SQLAlchemy is used for
SQLAlchemy vs the alternatives makers chose
For database access & ORMs, 1 of the 50 makers' products we know the choice of picked SQLAlchemy (2%), behind Prisma (74%).
| Option | Makers' products | Open source | |
|---|---|---|---|
| 37 74% | Yes | ||
| 12 24% | Yes | ||
| 1 2% | Yes |
For database access & ORMs: how many of the 50 makers' products we know the database access & ORMs of chose each option.
When to use SQLAlchemy, and when not
Pick SQLAlchemy if
- Your backend is Python and not Django. Database Access & ORMs →
Something else fits better if
- You want one schema file that generates types, migrations and a readable query API: Prisma.
- You deploy to serverless or edge functions and want queries that read like SQL, fully typed: Drizzle ORM.
- You already write SQL comfortably and only want types around it, no schema layer: Kysely.
SQLAlchemy is the database library most Python web apps use when they are not built on Django. It lets Python code define tables, build queries and map rows to objects across many databases without hand-built SQL strings.
More about SQLAlchemy
It has two layers. Core handles engines, connection pooling, dialects and the SQL Expression Language, a way of composing SQL statements from Python objects and running them in a transaction. The ORM sits on top. You map classes to tables, and a Session tracks changes to those objects and turns them into INSERT, UPDATE and DELETE statements when you commit, a pattern called "unit of work". You can use Core alone or both together. Version 2.1 is the current release series and requires Python 3.11 or newer.
What a team gets: built-in dialects for PostgreSQL, MySQL and MariaDB, SQLite, Oracle and SQL Server, with external dialects for CockroachDB, ClickHouse, Redshift, Databricks and others; asyncio support for both Core and the ORM through async drivers such as asyncpg and aiosqlite; and fine control over how relationships load. Schema migrations are handled by Alembic, a separate tool from the same authors that can autogenerate migration scripts from your models. It is an MIT-licensed library that runs inside your app.
Limits: SQLAlchemy is large, and its ORM rewards learning how sessions, loading strategies and transactions interact. In async code, lazy-loaded relationships must be avoided or loaded explicitly, since attribute access cannot quietly run a query. Alembic's autogenerate needs manual review and cannot detect renames.
How SQLAlchemy itself is built
4 tools, from its own code, website and Product Hunt page.
SQLAlchemy pros and cons
What makers like most: Its data-mapper and query-object style makes SQL reusable and composable without hiding the database, from simple selects to multi-join aggregates. Their most common complaint: It feels complicated, and it is hard to see what SQL it actually runs or spot hidden queries in loops.
Pros
- Its data-mapper and query-object style makes SQL reusable and composable without hiding the database, from simple selects to multi-join aggregates. HNHN 2HN 3
- Mapping rows to objects removes serialization boilerplate and makes schema changes less painful than hand-written SQL. HNHN 2HN 3
- SQLAlchemy Core works as a plain query builder when you do not want the ORM layer. HNHN 2
- Paired with Alembic, it gives model-driven migrations without pulling in all of Django. HNHN 2
Cons and watch-outs
- It feels complicated, and it is hard to see what SQL it actually runs or spot hidden queries in loops. HNHN 2HN 3HN 4
- Operator-overloaded expressions and sprawling signatures confuse type checkers and cause footguns like comparisons that are always truthy. HNHN 2HN 3
- Lazy-loaded relationships make N+1 query problems easy to create. HNHN 2
- Its client-side pool conflicts with PgBouncer, reusing killed connections and clashing with prepared statements. HNHN 2
Themes that recur in makers' words and Hacker News comments, each linked to what it summarises.
What Hacker News says about SQLAlchemy
On Hacker News, 23% of comments about SQLAlchemy recommend it and 14% criticize it: net praise +9%, the least liked of 4 tools HN discusses for database access & ORMs.
By year
| Year | Comments choosing it, per month | Net praise |
|---|---|---|
| 2023 | 1.8 | +16% |
| 2024 | 1.2 | −10% |
| 2025 | 3.7 | +25% |
| 2026 (8 mo) | 2.1 | −9% |
In their words
- “Every time I use an ORM (SQLAlchemy mostly, the one mentioned in the article) I am 100% sure what SQL” HN, Jul 2026
- “SQLAlchemy has its own frozendict which we've had in use for many years” HN, Dec 2025
- “it's much easier to reason about than SQLAlchemy's event system” HN, Mar 2026
Hacker News comments January 2023 to August 2026 that name SQLAlchemy in a sentence like "I use" or "we moved to", Claude read a sample of 100 and the counts scale it to all of them; net praise is comments recommending it minus comments criticizing it, as a share of all comments about it. How it's counted, and how HN compares with makers.
Reliability and open issues
The most wanted open issue on GitHub has 35 👍.
Most wanted on GitHub
- Complete SQLAlchemy inline pep484 typing👍 35 · opened Jul 2021 · active Aug 2026
Who uses it
1 makers' products, each linked to the source that shows it, and 221 open-source projects that declare it in their code.
None of these in makers' own words.
Open source: a project that declares SQLAlchemy as a dependency in its public code — verifiable, but not necessarily a live product.
What its projects tell coding agents
What open-source projects' AGENTS.md and CLAUDE.md files say about SQLAlchemy, in our words — from the 20 files that name it:
Named as the Python ORM, usually with FastAPI or Flask and PostgreSQL.10 files
Keep SQLAlchemy models and database code in dedicated db or models modules, separate from handlers.4 files
Use SQLAlchemy 2.0-style APIs with typed mapped columns and select, not legacy query patterns.3 files
79 of the 146 open-source products built with SQLAlchemy that were worked on in the last 180 days keep instruction files for coding agents — 54%, against 53% of all the projects we read. AGENTS.md is in 60, CLAUDE.md in 57.
Alternatives to SQLAlchemy
All alternatives by situation →Questions makers ask about SQLAlchemy
What is SQLAlchemy used for?
Python SQL toolkit and ORM, the standard way Python apps outside Django talk to relational databases. Makers' products we track use it for database access & ORMs (1).
What are the pros and cons of SQLAlchemy?
Pros makers name: Its data-mapper and query-object style makes SQL reusable and composable without hiding the database, from simple selects to multi-join aggregates. Mapping rows to objects removes serialization boilerplate and makes schema changes less painful than hand-written SQL. SQLAlchemy Core works as a plain query builder when you do not want the ORM layer. Cons: It feels complicated, and it is hard to see what SQL it actually runs or spot hidden queries in loops. Operator-overloaded expressions and sprawling signatures confuse type checkers and cause footguns like comparisons that are always truthy. Lazy-loaded relationships make N+1 query problems easy to create.
What are the alternatives to SQLAlchemy?
For database access & ORMs, the other options makers' products we track chose most are Prisma (37), Drizzle ORM (12). Open source or self-hostable among them: Prisma, Drizzle ORM. Each alternative, with the situation it fits, is on the SQLAlchemy alternatives page.
When should you use SQLAlchemy?
Your backend is Python and not Django (database access & ORMs). Something else fits better if: you want one schema file that generates types, migrations and a readable query API, pick Prisma; you deploy to serverless or edge functions and want queries that read like SQL, fully typed, pick Drizzle ORM.
Which databases does SQLAlchemy support?
Included dialects cover PostgreSQL, MySQL and MariaDB, SQLite, Oracle and Microsoft SQL Server, each needing its DBAPI driver installed. Maintained external dialects add databases such as CockroachDB, ClickHouse, Amazon Redshift and Databricks. source ↗
Which Python versions does it need?
SQLAlchemy 2.1 targets Python 3.11 and above. Asyncio support is an extra; install sqlalchemy[asyncio] to get the greenlet dependency, which 2.1 no longer installs by default. source ↗
Do I have to use the ORM?
No. Core and its SQL Expression Language work on their own, building SQL from composable Python objects and running it against the database. The ORM is an optional layer that adds object mapping and unit-of-work persistence. source ↗
Can I use it with asyncio (FastAPI and similar)?
Yes. Both Core and the ORM support asyncio through async-compatible dialects such as asyncpg and aiosqlite, but your code must avoid implicit IO, such as lazy-loaded relationships, using eager loading or the AsyncAttrs mixin instead. source ↗
How do I handle schema migrations?
With Alembic, a lightweight migration tool built for SQLAlchemy. Its autogenerate feature drafts migrations from your models, but the scripts always need review; it cannot detect table or column renames (they appear as drop and add) or unnamed constraints. source ↗
Is SQLAlchemy free?
Yes — it is free, open-source software.
Is SQLAlchemy open source or self-hostable?
Open source, and you can self-host it. source ↗
Can AI coding agents work with SQLAlchemy?
No llms.txt, official MCP server or CLI found yet.
Who uses SQLAlchemy?
1 makers' products we track, each with a source, and 221 open-source projects declare it in their code. source ↗