Core and ORM Examples

The SQLAlchemy distribution includes a variety of code examples illustrating a select set of patterns, some typical and some not so typical. All are runnable and can be found in the /examples directory of the distribution. Descriptions and source code for all can be found here.

Additional SQLAlchemy examples, some user contributed, are available on the wiki at https://www.sqlalchemy.org/trac/wiki/UsageRecipes.

Mapping Recipes

Adjacency List

Associations

Asyncio Integration

Directed Graphs

Dynamic Relations as Dictionaries

Generic Associations

Materialized Paths

Nested Sets

Performance

Space Invaders

Versioning Objects

Versioning with a History Table

Versioning using Temporal Rows

Vertical Attribute Mapping

Inheritance Mapping Recipes

Basic Inheritance Mappings

Special APIs

Attribute Instrumentation

Horizontal Sharding

Extending Core

Extending Statements like SELECT, INSERT, etc

Extending the ORM

ORM Query Events

Dogpile Caching