---
name: "sqlalchemy"
description: "Scraped from https://docs.sqlalchemy.org/en/20/ Source: https://docs.sqlalchemy.org/en/20/. Use when questions involve: _modules, changelog, core, dialects, faq, orm."
---

# Sqlalchemy

> Official documentation: https://docs.sqlalchemy.org/en/20/

## Overview

This skill provides comprehensive documentation for sqlalchemy.

**Total references:** 117 files (~1,424,225 tokens)

**Topics covered:**
080b2, Proxying to Dictionary Based Collections, Backend-specific UPPERCASE datatypes, Dialect support for psycopg 3 aka psycopg, 1110, Marking Implicitly Generated Values timestamps and Triggered Columns, Behavioral Changes Backwards Incompatible, Custom Version Counters  Types, Scalar Relationships, Overriding Reflected Columns, The select SQL Expression Construct, Type System Changes...

## Reference Files

Load only the reference files relevant to the user's question:

### _Modules

- **[SQLAlchemy 2.0 Documentation and more](references/_modules-1.md)** (~7,719 tokens)
- **[SQLAlchemy 2.0 Documentation and more](references/_modules-2.md)** (~7,528 tokens)
- **[SQLAlchemy 2.0 Documentation and more](references/_modules-3.md)** (~7,546 tokens)
- **[SQLAlchemy 2.0 Documentation and more](references/_modules-4.md)** (~7,980 tokens)
- **[SQLAlchemy 2.0 Documentation and more](references/_modules-5.md)** (~3,328 tokens)

### Changelog

- **[SQLAlchemy 2.0 Documentation and more](references/changelog-1.md)** (~7,828 tokens)
  - Topics: 017, 016, 015
- **[SQLAlchemy 2.0 Documentation](references/changelog-2.md)** (~11,321 tokens)
  - Topics: 0311, 0310, 039
- **[SQLAlchemy 2.0 Documentation](references/changelog-3.md)** (~17,582 tokens)
  - Topics: 048, 047p1, 047
- **[SQLAlchemy 2.0 Documentation](references/changelog-4.md)** (~15,424 tokens)
  - Topics: 059, 058, 057
- **[SQLAlchemy 2.0 Documentation](references/changelog-5.md)** (~25,207 tokens)
  - Topics: 069, 068, 067
- **[SQLAlchemy 2.0 Documentation](references/changelog-6.md)** (~20,140 tokens)
  - Topics: 0711, 0710, 079
- **[SQLAlchemy 2.0 Documentation](references/changelog-7.md)** (~19,892 tokens)
  - Topics: 087, 086, 085
- **[SQLAlchemy 2.0 Documentation](references/changelog-8.md)** (~28,199 tokens)
  - Topics: 0910, 099, 098
- **[SQLAlchemy 2.0 Documentation](references/changelog-9.md)** (~29,711 tokens)
  - Topics: 1019, 1018, 1017
- **[SQLAlchemy 2.0 Documentation](references/changelog-10.md)** (~16,766 tokens)
  - Topics: 1118, 1117, 1116
- **[SQLAlchemy 2.0 Documentation](references/changelog-11.md)** (~21,928 tokens)
  - Topics: 1219, 1218, 1217
- **[SQLAlchemy 2.0 Documentation](references/changelog-12.md)** (~26,369 tokens)
  - Topics: 1325, 1324, 1323
- **[SQLAlchemy 2.0 Documentation](references/changelog-13.md)** (~62,316 tokens)
  - Topics: 1455, 1454, 1453
- **[SQLAlchemy 2.0 Documentation](references/changelog-14.md)** (~58,618 tokens)
  - Topics: 2047, 2046, 2045
- **[SQLAlchemy 2.0 Documentation and more](references/changelog-15.md)** (~4,111 tokens)
  - Topics: Current Migration Guide, Change logs, Older Migration Guides
- **[SQLAlchemy 2.0 Documentation](references/changelog-16.md)** (~4,186 tokens)
  - Topics: Major Documentation Changes, Deprecations Source, Requirements Changes
- **[SQLAlchemy 2.0 Documentation](references/changelog-17.md)** (~7,710 tokens)
  - Topics: Platform Support, New Dialect System, Expression Language Changes
- **[SQLAlchemy 2.0 Documentation](references/changelog-18.md)** (~8,149 tokens)
  - Topics: Introduction, New Features, Behavioral Changes Backwards Compatible
- **[SQLAlchemy 2.0 Documentation](references/changelog-19.md)** (~7,818 tokens)
  - Topics: Introduction, Platform Support, New ORM Features
- **[SQLAlchemy 2.0 Documentation](references/changelog-20.md)** (~11,385 tokens)
  - Topics: Introduction, Platform Support, Behavioral Changes - ORM
- **[SQLAlchemy 2.0 Documentation](references/changelog-21.md)** (~16,373 tokens)
  - Topics: Introduction, New Features and Improvements - ORM, New Features and Improvements - Core
- **[SQLAlchemy 2.0 Documentation](references/changelog-22.md)** (~18,629 tokens)
  - Topics: Introduction, Platform  Installer Changes, New Features and Improvements - ORM
- **[SQLAlchemy 2.0 Documentation](references/changelog-23.md)** (~10,644 tokens)
  - Topics: Introduction, Platform Support, New Features and Improvements - ORM
- **[SQLAlchemy 2.0 Documentation](references/changelog-24.md)** (~11,516 tokens)
  - Topics: Introduction, General, New Features and Improvements - ORM
- **[SQLAlchemy 2.0 Documentation](references/changelog-25.md)** (~24,601 tokens)
  - Topics: Major API changes and features - General, API and Behavioral Changes - Core, New Features - ORM
- **[SQLAlchemy 2.0 Documentation](references/changelog-26.md)** (~14,986 tokens)
  - Topics: The 14-20 Migration Path, 1x - 2x Migration Overview, 20 Migration - Core Connection  Transaction
- **[SQLAlchemy 2.0 Documentation](references/changelog-27.md)** (~14,599 tokens)
  - Topics: New Typing Support in Core and ORM - Stubs  Extensions no longer used, Optimized ORM bulk insert now implemented for all backends other than MySQL, ORM-enabled Insert Upsert Update and Delete Statements with ORM RETURNING

### Core

- **[SQLAlchemy 2.0 Documentation and more](references/core-1.md)** (~2,837 tokens)
  - Topics: Synopsis, Dialect-specific compilation rules, Compiling sub-elements of a custom expression construct
- **[SQLAlchemy 2.0 Documentation](references/core-2.md)** (~44,025 tokens)
  - Topics: Basic Usage, Using Transactions, Setting Transaction Isolation Levels including DBAPI Autocommit
- **[SQLAlchemy 2.0 Documentation](references/core-3.md)** (~15,926 tokens)
  - Topics: Defining Foreign Keys, UNIQUE Constraint, CHECK Constraint
- **[SQLAlchemy 2.0 Documentation](references/core-4.md)** (~10,435 tokens)
  - Topics: Overriding Type Compilation, Augmenting Existing Types, TypeDecorator Recipes
- **[SQLAlchemy 2.0 Documentation](references/core-5.md)** (~5,159 tokens)
  - Topics: Custom DDL, Controlling DDL Sequences, Using the built-in DDLElement Classes
- **[SQLAlchemy 2.0 Documentation](references/core-6.md)** (~8,390 tokens)
  - Topics: Scalar Defaults, Python-Executed Functions, Client-Invoked SQL Expressions
- **[SQLAlchemy 2.0 Documentation](references/core-7.md)** (~8,492 tokens)
  - Topics: DML Foundational Constructors, DML Class Documentation Constructors
- **[SQLAlchemy 2.0 Documentation](references/core-8.md)** (~10,299 tokens)
  - Topics: Supported Databases, Database URLs, Engine Creation API
- **[SQLAlchemy 2.0 Documentation and more](references/core-9.md)** (~3,016 tokens)
  - Topics: Event Registration, Named Argument Styles, Targets
- **[SQLAlchemy 2.0 Documentation](references/core-10.md)** (~11,178 tokens)
  - Topics: Connection Pool Events, SQL Execution and Connection Events, Schema Events
- **[SQLAlchemy 2.0 Documentation and more](references/core-11.md)** (~5,878 tokens)
- **[SQLAlchemy 2.0 Documentation and more](references/core-12.md)** (~6,173 tokens)
  - Topics: Function API, Selected Known Functions, Available Inspection Targets
- **[SQLAlchemy 2.0 Documentation](references/core-13.md)** (~33,902 tokens)
- **[SQLAlchemy 2.0 Documentation](references/core-14.md)** (~26,566 tokens)
  - Topics: Accessing Tables and Columns, Creating and Dropping Database Tables, Altering Database Objects through Migrations
- **[SQLAlchemy 2.0 Documentation](references/core-15.md)** (~3,129 tokens)
  - Topics: Comparison Operators, IN Comparisons, Identity Comparisons
- **[SQLAlchemy 2.0 Documentation](references/core-16.md)** (~11,250 tokens)
  - Topics: Connection Pool Configuration, Switching Pool Implementations, Using a Custom Connection Function
- **[SQLAlchemy 2.0 Documentation](references/core-17.md)** (~11,385 tokens)
  - Topics: Overriding Reflected Columns, Reflecting Views, Reflecting All Tables at Once
- **[SQLAlchemy 2.0 Documentation](references/core-18.md)** (~829 tokens)
- **[SQLAlchemy 2.0 Documentation](references/core-19.md)** (~49,969 tokens)
  - Topics: Selectable Foundational Constructors, Selectable Modifier Constructors, Selectable Class Documentation
- **[SQLAlchemy 2.0 Documentation](references/core-20.md)** (~484 tokens)
- **[SQLAlchemy 2.0 Documentation](references/core-21.md)** (~37,293 tokens)
  - Topics: Column Element Foundational Constructors, Column Element Modifier Constructors, Column Element Class Documentation
- **[SQLAlchemy 2.0 Documentation and more](references/core-22.md)** (~5,024 tokens)
- **[SQLAlchemy 2.0 Documentation](references/core-23.md)** (~24,572 tokens)
  - Topics: The CamelCase datatypes, The UPPERCASE datatypes, Backend-specific UPPERCASE datatypes
- **[SQLAlchemy 2.0 Documentation and more](references/core-24.md)** (~3,559 tokens)

### Dialects

- **[SQLAlchemy 2.0 Documentation](references/dialects-1.md)** (~702 tokens)
  - Topics: Included Dialects, External Dialects
- **[SQLAlchemy 2.0 Documentation](references/dialects-2.md)** (~11,761 tokens)
  - Topics: DBAPI Support, External Dialects, Auto Increment Behavior  IDENTITY Columns
- **[SQLAlchemy 2.0 Documentation](references/dialects-3.md)** (~13,592 tokens)
  - Topics: DBAPI Support, Supported Versions and Features, Connection Timeouts and Disconnects
- **[SQLAlchemy 2.0 Documentation](references/dialects-4.md)** (~15,479 tokens)
  - Topics: DBAPI Support, Auto Increment Behavior, Transaction Isolation Level  Autocommit
- **[SQLAlchemy 2.0 Documentation](references/dialects-5.md)** (~28,713 tokens)
  - Topics: DBAPI Support, SequencesSERIALIDENTITY, Server Side Cursors
- **[SQLAlchemy 2.0 Documentation](references/dialects-6.md)** (~11,111 tokens)
  - Topics: DBAPI Support, Date and Time Types, SQLite Auto Incrementing Behavior

### Faq

- **[SQLAlchemy 2.0 Documentation and more](references/faq-1.md)** (~5,749 tokens)
  - Topics: How do I configure logging, How do I pool database connections   Are my connections pooled, How do I pass custom connect arguments to my database API
- **[SQLAlchemy 2.0 Documentation and more](references/faq-2.md)** (~6,572 tokens)
  - Topics: How do I map a table that has no primary key, How do I configure a Column that is a Python reserved word or similar, How do I get a list of all columns relationships mapped attributes etc given a mapped class
- **[SQLAlchemy 2.0 Documentation](references/faq-3.md)** (~4,680 tokens)
  - Topics: Im re-loading data with my Session but it isnt seeing changes that I committed elsewhere, This Sessions transaction has been rolled back due to a previous exception during flush or similar, How do I make a Query that always adds a certain filter to every query
- **[SQLAlchemy 2.0 Documentation and more](references/faq-4.md)** (~3,829 tokens)
  - Topics: How do I render SQL expressions as strings possibly with bound parameters inlined, Why are percent signs being doubled up when stringifying SQL statements, Im using op to generate a custom operator and my parenthesis are not coming out correctly

### General

- **[SQLAlchemy 2.0 Documentation](references/general-1.md)** (~863 tokens)
  - Topics: Indices and tables
- **[SQLAlchemy 2.0 Documentation](references/general-2.md)** (~14,066 tokens)
  - Topics: Connections and Transactions, DBAPI Errors, SQL Expression Language
- **[SQLAlchemy 2.0 Documentation](references/general-3.md)** (~10,496 tokens)
- **[SQLAlchemy 2.0 Documentation and more](references/general-4.md)** (~2,817 tokens)
  - Topics: Documentation Overview, Code Examples, Installation Guide

### Orm

- **[SQLAlchemy 2.0 Documentation and more](references/orm-1.md)** (~7,668 tokens)
  - Topics: Backref Default Arguments, Specifying Backref Arguments, Declarative vs Imperative Forms
- **[SQLAlchemy 2.0 Documentation](references/orm-2.md)** (~5,634 tokens)
  - Topics: save-update, delete, delete-orphan
- **[SQLAlchemy 2.0 Documentation](references/orm-3.md)** (~8,162 tokens)
  - Topics: Customizing Collection Access, Custom Collection Implementations, Collection API
- **[SQLAlchemy 2.0 Documentation](references/orm-4.md)** (~3,113 tokens)
  - Topics: Working with Mapped Composite Column Types, Other mapping forms for composites, Using Legacy Non-Dataclasses
- **[SQLAlchemy 2.0 Documentation](references/orm-5.md)** (~11,905 tokens)
  - Topics: Implicit Method Access, Thread-Local Scope, Using Thread-Local Scope with Web Applications
- **[SQLAlchemy 2.0 Documentation and more](references/orm-6.md)** (~7,995 tokens)
  - Topics: Declarative Dataclass Mapping, Applying ORM Mappings to an existing dataclass legacy dataclass use, Applying ORM mappings to an existing attrs class
- **[SQLAlchemy 2.0 Documentation and more](references/orm-7.md)** (~6,138 tokens)
  - Topics: Augmenting the Base, Mixing in Columns, Mixing in Relationships
- **[SQLAlchemy 2.0 Documentation](references/orm-8.md)** (~12,335 tokens)
  - Topics: Declarative Table withmapped_column, ORM Annotated Declarative - Complete Guide, Declarative with Imperative Table aka Hybrid Declarative
- **[SQLAlchemy 2.0 Documentation](references/orm-9.md)** (~18,903 tokens)
  - Topics: Session Events, Mapper Events, Instance Events
- **[SQLAlchemy 2.0 Documentation and more](references/orm-10.md)** (~5,228 tokens)
  - Topics: Mapping Recipes, Inheritance Mapping Recipes, Special APIs
- **[SQLAlchemy 2.0 Documentation](references/orm-11.md)** (~29,911 tokens)
  - Topics: Simplifying Scalar Collections, Simplifying Association Objects, Proxying to Dictionary Based Collections
- **[SQLAlchemy 2.0 Documentation](references/orm-12.md)** (~24,793 tokens)
  - Topics: Asyncio Platform Installation Notes Including Apple M1, Synopsis - Core, Synopsis - ORM
- **[SQLAlchemy 2.0 Documentation](references/orm-13.md)** (~5,889 tokens)
  - Topics: Basic Use, Generating Mappings from an Existing MetaData, Generating Mappings from Multiple Schemas
- **[SQLAlchemy 2.0 Documentation and more](references/orm-14.md)** (~7,992 tokens)
  - Topics: Synopsis, Performance, Rationale
- **[SQLAlchemy 2.0 Documentation and more](references/orm-15.md)** (~7,542 tokens)
  - Topics: Defining Expression Behavior Distinct from Attribute Behavior, Usinginplaceto create pep-484 compliant hybrid properties, Defining Setters
- **[SQLAlchemy 2.0 Documentation and more](references/orm-16.md)** (~5,933 tokens)
  - Topics: API Reference, Establishing Mutability on Scalar Column Values, Establishing Mutability on Composites
- **[SQLAlchemy 2.0 Documentation and more](references/orm-17.md)** (~5,951 tokens)
  - Topics: Installation, What the Plugin Does, Usage
- **[SQLAlchemy 2.0 Documentation](references/orm-18.md)** (~7,242 tokens)
  - Topics: Joined Table Inheritance, Single Table Inheritance, Concrete Table Inheritance
- **[SQLAlchemy 2.0 Documentation](references/orm-19.md)** (~19,596 tokens)
- **[SQLAlchemy 2.0 Documentation](references/orm-20.md)** (~7,737 tokens)
  - Topics: Handling Multiple Join Paths, Specifying Alternate Join Conditions, Creating Custom Foreign Conditions
- **[SQLAlchemy 2.0 Documentation](references/orm-21.md)** (~6,719 tokens)
  - Topics: Write Only Relationships, Dynamic Relationship Loaders, Setting RaiseLoad
- **[SQLAlchemy 2.0 Documentation and more](references/orm-22.md)** (~6,242 tokens)
  - Topics: Simple Validators, Using Custom Datatypes at the Core Level, Using Descriptors and Hybrids
- **[SQLAlchemy 2.0 Documentation](references/orm-23.md)** (~17,654 tokens)
- **[SQLAlchemy 2.0 Documentation and more](references/orm-24.md)** (~5,892 tokens)
  - Topics: ORM Mapping Styles, Mapped Class Essential Components, Mapped Class Behavior
- **[SQLAlchemy 2.0 Documentation](references/orm-25.md)** (~5,933 tokens)
  - Topics: Embedding SQL InsertUpdate Expressions into a Flush, Using SQL Expressions with Sessions, Forcing NULL on a column with a default
- **[SQLAlchemy 2.0 Documentation](references/orm-26.md)** (~7,221 tokens)
  - Topics: ORM Loader Options, ORM Execution Options
- **[SQLAlchemy 2.0 Documentation](references/orm-27.md)** (~6,717 tokens)
  - Topics: Limiting which Columns Load with Column Deferral, Configuring Column Deferral on Mappings, Loading Arbitrary SQL Expressions onto Objects
- **[SQLAlchemy 2.0 Documentation](references/orm-28.md)** (~8,349 tokens)
  - Topics: ORM Bulk INSERT Statements, ORM Bulk UPDATE by Primary Key, ORM UPDATE and DELETE with Custom WHERE Criteria
- **[SQLAlchemy 2.0 Documentation](references/orm-29.md)** (~1,066 tokens)
- **[SQLAlchemy 2.0 Documentation](references/orm-30.md)** (~7,126 tokens)
  - Topics: SELECTing from the base class vs specific sub-classes, Using selectin_polymorphic, Using with_polymorphic
- **[SQLAlchemy 2.0 Documentation](references/orm-31.md)** (~11,610 tokens)
  - Topics: The Query Object, ORM-Specific Query Constructs
- **[SQLAlchemy 2.0 Documentation](references/orm-32.md)** (~11,703 tokens)
  - Topics: Summary of Relationship Loading Styles, Configuring Loader Strategies at Mapping Time, Relationship Loading with Loader Options
- **[SQLAlchemy 2.0 Documentation](references/orm-33.md)** (~6,977 tokens)
  - Topics: Selecting ORM Entities and Attributes, Joins, Relationship WHERE Operators
- **[SQLAlchemy 2.0 Documentation](references/orm-34.md)** (~3,071 tokens)
  - Topics: Declare Models, Create an Engine, Emit CREATE TABLE DDL
- **[SQLAlchemy 2.0 Documentation](references/orm-35.md)** (~6,171 tokens)
- **[SQLAlchemy 2.0 Documentation and more](references/orm-36.md)** (~4,852 tokens)
  - Topics: Rows that point to themselves  Mutually Dependent Rows, Mutable Primary Keys  Update Cascades, Composite Adjacency Lists
- **[SQLAlchemy 2.0 Documentation](references/orm-37.md)** (~16,599 tokens)
  - Topics: Session and sessionmaker, Session Utilities, Attribute and State Management Utilities
- **[SQLAlchemy 2.0 Documentation](references/orm-38.md)** (~8,052 tokens)
  - Topics: What does the Session do, Basics of Using a Session, Session Frequently Asked Questions
- **[SQLAlchemy 2.0 Documentation](references/orm-39.md)** (~4,703 tokens)
  - Topics: Execute Events, Persistence Events, Object Lifecycle Events
- **[SQLAlchemy 2.0 Documentation](references/orm-40.md)** (~4,843 tokens)
  - Topics: Quickie Intro to Object States, Session Attributes, Session Referencing Behavior
- **[SQLAlchemy 2.0 Documentation and more](references/orm-41.md)** (~6,090 tokens)
  - Topics: Managing Transactions, Joining a Session into an External Transaction such as for test suites, Simple Version Counting

### Tutorial

- **[SQLAlchemy 2.0 Documentation and more](references/tutorial-1.md)** (~2,675 tokens)
  - Topics: The insert SQL Expression Construct, Executing the Statement, INSERT usually generates the values clause automatically
- **[SQLAlchemy 2.0 Documentation](references/tutorial-2.md)** (~12,148 tokens)
  - Topics: The select SQL Expression Construct, Setting the COLUMNS and FROM clause, The WHERE clause
- **[SQLAlchemy 2.0 Documentation and more](references/tutorial-3.md)** (~7,582 tokens)
  - Topics: The update SQL Expression Construct, The delete SQL Expression Construct, Getting Affected Row Count from UPDATE DELETE
- **[SQLAlchemy 2.0 Documentation](references/tutorial-4.md)** (~5,051 tokens)
  - Topics: Setting up MetaData with Table objects, Using ORM Declarative Forms to Define Table Metadata, Table Reflection
- **[SQLAlchemy 2.0 Documentation](references/tutorial-5.md)** (~4,325 tokens)
  - Topics: Inserting Rows using the ORM Unit of Work pattern, Updating ORM Objects using the Unit of Work pattern, Deleting ORM Objects using the Unit of Work pattern
- **[SQLAlchemy 2.0 Documentation](references/tutorial-6.md)** (~4,878 tokens)
  - Topics: Persisting and Loading Relationships, Loading Relationships, Using Relationships in Queries

## Usage Guidelines

1. **Identify relevant sections** - Match the user's question to the appropriate reference file(s)
2. **Load minimally** - Only read files directly relevant to the question to conserve context
3. **Cite sources** - Reference specific sections when answering
4. **Combine knowledge** - For complex questions, you may need multiple reference files

### When to use each reference:

- **_Modules**: _Modules-related features and documentation
- **Changelog**: Changelog-related features and documentation
- **Core**: Core-related features and documentation
- **Dialects**: Dialects-related features and documentation
- **Faq**: Faq-related features and documentation
- **General**: General documentation, overview, and getting started
- **Orm**: Orm-related features and documentation
- **Tutorial**: Tutorial-related features and documentation
