Table of Contents
class Table: Metadata for one table
class ForeignKeyConstraint: Specifying a relation to another table
class PrimaryKeyConstraint: Describing a table's primary key
class UniqueConstraint: Describing a uniqueness constraint on a table
class Index: Specifying an index on a table
class Column: Metadata for one table column
class ForeignKey: Specifying a column's foreign key relation
class Sequence: Specifying an auto-incrementing column
reflector: Script to show an existing database's structure
This document summarizes some of the more commonly used features of the SQLAlchemy system. The purpose of the SQLAlchemy system is to provide a connection between your Python program and any of several classic database systems built on top of SQL (Structured Query Language) such as MySQL, Postgres, or Oracle.
You should have general knowledge of relational databases, and the additional problems of object-relational mappers, or the current document will not make much sense to you.
Assuming you understand how a classical SQL database works, SQLAlchemy can make life much easier for these applications and many more:
You can use SQLAlchemy to connect to applications in other languages, using classical SQL database engines to interchange data.
You can use SQLAlchemy to provide a persistence layer, so that some of the objects within your Python application can be stored in external databases for later retrieval and translation back into live objects.
This document is not a complete reference. It is intended for daily reference to functions necessary to put up fairly simple applications. SQLAlchemy is a full-featured and highly tuneable system, and we will not cover here many of its useful features for improved performance and simplified programming. Please refer to the SQLAlchemy home page for tutorials and detailed reference information.
Section 9, “
reflector: Script to show an existing database's
structure” is a script that uses
reflection to determine the structure of an existing
For a sizeable working example, see
Python interface to the Christmas Bird Count