The Python SQL toolkit and Object Relational Mapper
open sourceMITfree
SQLAlchemy is the SQL toolkit and object relational mapper for Python that gives application developers the full power and flexibility of SQL. It has two parts: the Core, a SQL abstraction layer with a SQL Expression Language for writing queries as Python expressions, a schema system that emits DDL and introspects existing databases, and a type system; and the optional ORM built on it, with a unit of work that batches writes in transactions, identity mapping and eager loading of related objects. It never generates schemas or relies on naming conventions, lets you swap in hand-written SQL, and includes dialects for PostgreSQL, MySQL and MariaDB, SQLite, Oracle and Microsoft SQL Server with sync and asyncio drivers, while other databases have external dialects.
Problems it solves
- map Python classes to database tables and query them without writing raw SQL everywhere
- write database queries in Python that work on PostgreSQL, MySQL and SQLite
- build complex SQL queries programmatically in Python with joins and subqueries
- an ORM for Python that still lets me drop down to hand-written SQL
- use async database access in a Python web app
- load related objects efficiently to avoid N+1 queries in Python
- introspect an existing database schema from Python
- a database layer for Flask or FastAPI apps that is not tied to Django
Features
- Core SQL Expression Language
- optional ORM with unit of work and identity map
- schema DDL generation and introspection
- dialects for PostgreSQL, MySQL/MariaDB, SQLite, Oracle and SQL Server
- sync and asyncio drivers
- eager and lazy loading strategies
- hand-written SQL can replace generated statements
- bind parameters for all literal values
Alternatives
The same job
These do what SQLAlchemy does.
