SQLAlchemy
The Database Toolkit for Python
The Database Toolkit for Python
  • home
  • features
    • Philosophy Statement
    • Feature Overview
    • Testimonials
  • news
  • documentation
    • Current Documentation (version 2.0)

    • Documentation by Version
    • Version 2.0
    • Version 1.4
    • Version 1.3

    • Talks and Tutorials
    • Published content overview
  • community
    • Get Support
    • Participate
    • Develop
    • Code of Conduct
    • Github
  • download
    • Download
    • Current Release Series (2.0)
    • Maintenance Release (1.4)
    • Development Access
    • License
    • Version Numbering
    • Release Status
Release: 1.4.46 legacy version | Release Date: January 3, 2023

SQLAlchemy 1.4 Documentation

SQLAlchemy 1.4 Documentation

legacy version

Home | Download this Documentation

SQLAlchemy ORM

  • ORM Quick Start
  • Object Relational Tutorial (1.x API)
  • ORM Mapped Class Configuration
    • ORM Mapped Class Overview
    • Mapping Classes with Declarative
    • Integration with dataclasses and attrs
    • Mapping Columns and Expressions¶
      • Mapping Table Columns
      • SQL Expressions as Mapped Attributes
      • Changing Attribute Behavior
      • Composite Column Types
    • Mapping Class Inheritance Hierarchies
    • Non-Traditional Mappings
    • Configuring a Version Counter
    • Class Mapping API
  • Relationship Configuration
  • Querying Data, Loading Objects
  • Using the Session
  • Events and Internals
  • ORM Extensions
  • ORM Examples

Project Versions

  • 1.4.46

Home | Download this Documentation

  • Previous: Integration with dataclasses and attrs
  • Next: Mapping Table Columns
  • Up: Home
    • SQLAlchemy ORM
      • ORM Mapped Class Configuration
  • On this page:
    • Mapping Columns and Expressions

Mapping Columns and Expressions¶

The following sections discuss how table columns and SQL expressions are mapped to individual object attributes.

  • Mapping Table Columns
    • Naming Columns Distinctly from Attribute Names
    • Automating Column Naming Schemes from Reflected Tables
    • Using column_property for column level options
      • column_property()
    • Mapping to an Explicit Set of Primary Key Columns
    • Mapping a Subset of Table Columns
  • SQL Expressions as Mapped Attributes
    • Using a Hybrid
    • Using column_property
      • Composing from Column Properties at Mapping Time
    • Using a plain descriptor
    • Query-time SQL expressions as mapped attributes
      • Using with_expression() with UNIONs, other subqueries
  • Changing Attribute Behavior
    • Simple Validators
      • validates()
    • Using Custom Datatypes at the Core Level
    • Using Descriptors and Hybrids
    • Synonyms
      • synonym()
    • Operator Customization
  • Composite Column Types
    • composite()
    • Tracking In-Place Mutations on Composites
    • Redefining Comparison Operations for Composites
    • Nesting Composites
Previous: Integration with dataclasses and attrs Next: Mapping Table Columns
© Copyright 2007-2023, the SQLAlchemy authors and contributors.

flambé! the dragon and The Alchemist image designs created and generously donated by Rotem Yaari.

Created using Sphinx 5.3.0. Documentation last generated: Wed 01 Feb 2023 11:51:33 AM

SQLAlchemy Sponsors

Python

Website content copyright © by SQLAlchemy authors and contributors. SQLAlchemy and its documentation are licensed under the MIT license.

SQLAlchemy is a trademark of Michael Bayer. mike(&)zzzcomputing.com All rights reserved.

Website generation by zeekofile, with huge thanks to the Blogofile project.

Mastodon