SQLAlchemy

Python SQL toolkit and ORM, the standard way Python apps outside Django talk to relational databases.

Ask your AI about this, with this page as the source:ChatGPT ↗Claude ↗Perplexity ↗

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.

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.

Where it fits

Who uses it

No maker's live product on record yet, and 185 open-source projects that declare it in their code.

Declared in code 185How evidence is collected →

We haven't found a maker's live product that uses SQLAlchemy yet — only the open-source projects below, which declare it in their code.

Aix-DBAix-DB 基于 LangChain/LangGraph 框架,结合 MCP Skills 多智能体协作架构,实现自然语言到数据洞察的端到端转换。Database Access & ORMsIn its code · source ↗

Open source: a project that declares SQLAlchemy as a dependency in its public code — verifiable, but not necessarily a live product.

Loved and watch-outs

Themes that recur in makers' words and Hacker News comments, each linked to what it summarises.

Most loved
  • 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
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

Reliability and open issues

Most wanted on GitHubOpen on 2026-10-04 in sqlalchemy/sqlalchemy, with activity in the last year — issues and feature requests by 👍.

Alternatives to SQLAlchemy

All alternatives by situation →

Questions makers ask about SQLAlchemy

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?

No maker's live product we track yet; 185 open-source projects declare it in their code. source ↗