SQLAlchemy 0.3 Documentation
Table of Contents
(view full table)- Tutorial
- Database Engines
- Database Meta Data
- Constructing SQL Queries via Python Expressions
- Data Mapping
- Session / Unit of Work
- Advanced Data Mapping
- The Types System
- Connection Pooling
- Plugins
- Generated Documentation
Table of Contents: Full
(view brief table)- Tutorial
- Installation
- Getting Started
- SQLAlchemy is Two Libraries in One
- Working with Database Objects
- Defining Metadata, Binding to Engines
- Creating a Table
- Inserting Rows
- Selecting
- Working with Rows
- Table Relationships
- Working with Object Mappers
- Creating a Mapper
- Obtaining a Session
- The Query Object
- Making Changes
- Saving
- Relationships
- Transactions
- Next Steps
- Database Engines
- Supported Databases
- create_engine() URL Arguments
- Database Engine Options
- More On Connections
- Using Transactions with Connection
- Connectionless Execution, Implicit Execution
- Configuring Logging
- Database Meta Data
- Describing Databases with MetaData
- Binding MetaData to an Engine or Connection
- Reflecting Tables
- Specifying the Schema Name
- ON UPDATE and ON DELETE
- Other Options
- Creating and Dropping Database Tables
- Column Defaults and OnUpdates
- Pre-Executed Insert Defaults
- Pre-Executed OnUpdate Defaults
- Inline Default Execution: PassiveDefault
- Defining Sequences
- Defining Constraints and Indexes
- Adapting Tables to Alternate Metadata
- Constructing SQL Queries via Python Expressions
- Simple Select
- Explicit Execution
- Binding ClauseElements to Engines
- Getting Results
- Using Column Labels
- Table/Column Specification
- WHERE Clause
- Inner and Outer Joins
- Table Aliases
- Subqueries
- Correlated Subqueries
- Unions
- Custom Bind Parameters
- Literal Text Blocks
- Building Select Objects
- Inserts
- Updates
- Deletes
- Data Mapping
- Basic Data Mapping
- Synopsis
- The Query Object
- Saving Objects
- Defining and Using Relationships
- Querying with Joins
- Loading Relationships
- More Relationships
- Session / Unit of Work
- Overview
- Object States
- Acquiring a Session
- Introduction to the Identity Map
- Whats Changed ?
- The Session API
- query()
- get()
- load()
- save()
- flush()
- close()
- delete()
- clear()
- refresh() / expire()
- expunge()
- bind_mapper() / bind_table()
- update()
- save_or_update()
- merge()
- Cascade rules
- SessionTransaction
- Advanced Data Mapping
- More On Mapper Properties
- Overriding Column Names
- Overriding Properties
- Custom List Classes
- Custom Join Conditions
- Lazy/Eager Joins Multiple Times to One Table
- Deferred Column Loading
- Working with Large Collections
- Relation Options
- Controlling Ordering
- Limiting Rows Combined with Eager Loads
- Mapping a Class with Table Inheritance
- Mapping a Class against Multiple Tables
- Mapping a Class against Arbitrary Selects
- Multiple Mappers for One Class
- Self Referential Mappers
- Statement and Result-Set ORM Queries
- Mapper Keyword Arguments
- Extending Mapper
- The Types System
- Connection Pooling
- Plugins
- SessionContext
- SelectResults
- assignmapper
- associationproxy
- orderinglist
- threadlocal
- ActiveMapper
- SqlSoup
- ProxyEngine
- Generated Documentation
- module sqlalchemy.sql
- Module Functions
- alias()
- and_()
- asc()
- between()
- between_()
- bindparam()
- case()
- cast()
- column()
- delete()
- desc()
- distinct()
- except_()
- except_all()
- exists()
- extract()
- insert()
- intersect()
- intersect_all()
- is_column()
- join()
- label()
- literal()
- literal_column()
- not_()
- null()
- or_()
- outerjoin()
- select()
- subquery()
- table()
- text()
- union()
- union_all()
- update()
- class AbstractDialect(object)
- class Alias(FromClause)
- class _BinaryExpression(ColumnElement)
- class _BindParamClause(ClauseElement,_CompareMixin)
- class _CalculatedClause(ColumnElement)
- class _Cast(ColumnElement)
- class ClauseElement(object)
- class ClauseList(ClauseElement)
- class ClauseParameters(object)
- class ClauseVisitor(object)
- class _ColumnClause(ColumnElement)
- class ColumnCollection(OrderedProperties)
- class ColumnElement(Selectable,_CompareMixin)
- class ColumnSet(OrderedSet)
- class _CompareMixin(object)
- class Compiled(ClauseVisitor)
- class CompoundSelect(_SelectBaseMixin,FromClause)
- class _Delete(_UpdateBase)
- class Executor(object)
- class _Exists(_UnaryExpression)
- class FromClause(Selectable)
- class _Function(_CalculatedClause,FromClause)
- class _FunctionGenerator(object)
- class _Grouping(ColumnElement)
- class _Insert(_UpdateBase)
- class Join(FromClause)
- class _Label(ColumnElement)
- class LoggingClauseVisitor(ClauseVisitor)
- class NoColumnVisitor(ClauseVisitor)
- class _Null(ColumnElement)
- class Select(_SelectBaseMixin,FromClause)
- class _SelectBaseMixin(object)
- class Selectable(ClauseElement)
- class TableClause(FromClause)
- class _TextClause(ClauseElement)
- class _TypeClause(ClauseElement)
- class _UnaryExpression(ColumnElement)
- class _Update(_UpdateBase)
- class _UpdateBase(ClauseElement)
- module sqlalchemy.schema
- Module Functions
- class BoundMetaData(MetaData)
- class CheckConstraint(Constraint)
- class Column(SchemaItem,_ColumnClause)
- class ColumnDefault(DefaultGenerator)
- class Constraint(SchemaItem)
- class DefaultGenerator(SchemaItem)
- class ForeignKey(SchemaItem)
- class ForeignKeyConstraint(Constraint)
- class Index(SchemaItem)
- class MetaData(SchemaItem)
- class PassiveDefault(DefaultGenerator)
- class PrimaryKeyConstraint(Constraint)
- class SchemaItem(object)
- class SchemaVisitor(ClauseVisitor)
- class Sequence(DefaultGenerator)
- class Table(SchemaItem,TableClause)
- class ThreadLocalMetaData(MetaData)
- class UniqueConstraint(Constraint)
- module sqlalchemy.types
- class BLOB(Binary)
- class BOOLEAN(Boolean)
- class Binary(TypeEngine)
- class Boolean(TypeEngine)
- class CHAR(String)
- class CLOB(TEXT)
- class DATE(Date)
- class DATETIME(DateTime)
- class DECIMAL(Numeric)
- class Date(TypeEngine)
- class DateTime(TypeEngine)
- class FLOAT(Float)
- class Float(Numeric)
- class INT(Integer)
- class Integer(TypeEngine)
- class Interval(TypeDecorator)
- class NCHAR(Unicode)
- class NullTypeEngine(TypeEngine)
- class Numeric(TypeEngine)
- class PickleType(MutableType,TypeDecorator)
- class SMALLINT(SmallInteger)
- class SmallInteger(Integer)
- class String(TypeEngine)
- class TEXT(String)
- class TIME(Time)
- class TIMESTAMP(DateTime)
- class Time(TypeEngine)
- class TypeDecorator(AbstractType)
- class TypeEngine(AbstractType)
- class Unicode(String)
- class VARCHAR(String)
- module sqlalchemy.engine
- Module Functions
- class BufferedColumnResultProxy(ResultProxy)
- class BufferedRowResultProxy(ResultProxy)
- class Connectable(Executor)
- class Connection(Connectable)
- class ConnectionProvider(object)
- class DefaultRunner(SchemaVisitor)
- class Dialect(AbstractDialect)
- class Engine(Connectable)
- class ExecutionContext(object)
- class ResultProxy(object)
- class RowProxy(object)
- class SchemaIterator(SchemaVisitor)
- class Transaction(object)
- module sqlalchemy.engine.url
- module sqlalchemy.engine.strategies
- class DefaultEngineStrategy(EngineStrategy)
- class EngineStrategy(object)
- class MockEngineStrategy(EngineStrategy)
- class PlainEngineStrategy(DefaultEngineStrategy)
- class ThreadLocalEngineStrategy(DefaultEngineStrategy)
- module sqlalchemy.engine.default
- class DefaultDialect(Dialect)
- class DefaultExecutionContext(ExecutionContext)
- class PoolConnectionProvider(ConnectionProvider)
- module sqlalchemy.engine.threadlocal
- class TLConnection(Connection)
- class TLEngine(Engine)
- class TLSession(object)
- class TLTransaction(Transaction)
- class TLocalConnectionProvider(PoolConnectionProvider)
- module sqlalchemy.ansisql
- class ANSICompiler(Compiled)
- class ANSIDefaultRunner(DefaultRunner)
- class ANSIDialect(DefaultDialect)
- class ANSIIdentifierPreparer(object)
- class ANSISchemaBase(SchemaIterator)
- class ANSISchemaDropper(ANSISchemaBase)
- class ANSISchemaGenerator(ANSISchemaBase)
- module sqlalchemy.orm
- Module Functions
- backref()
- cascade_mappers()
- class_mapper()
- clear_mapper()
- clear_mappers()
- column_property()
- compile_mappers()
- contains_alias()
- contains_eager()
- defer()
- deferred()
- eagerload()
- extension()
- lazyload()
- mapper()
- noload()
- object_mapper()
- object_session()
- polymorphic_union()
- relation()
- synonym()
- undefer()
- class MapperExtension(object)
- class Query(object)
- class Session(object)
- module sqlalchemy.orm.mapper
- module sqlalchemy.orm.interfaces
- class LoaderStrategy(object)
- class MapperOption(object)
- class MapperProperty(object)
- class OperationContext(object)
- class PropertyOption(MapperOption)
- class StrategizedOption(PropertyOption)
- class StrategizedProperty(MapperProperty)
- class SynonymProperty(MapperProperty)
- module sqlalchemy.orm.query
- module sqlalchemy.orm.session
- module sqlalchemy.exceptions
- class ArgumentError()
- class AssertionError()
- class CircularDependencyError()
- class CompileError()
- class ConcurrentModificationError()
- class DBAPIError()
- class FlushError()
- class InvalidRequestError()
- class NoSuchColumnError()
- class NoSuchTableError()
- class SQLAlchemyError()
- class SQLError()
- class TimeoutError()
- module sqlalchemy.pool
- Module Functions
- class AssertionPool(Pool)
- class NullPool(Pool)
- class Pool(object)
- class QueuePool(Pool)
- class SingletonThreadPool(Pool)
- class StaticPool(Pool)
- module sqlalchemy.ext.sessioncontext
- module sqlalchemy.mods.threadlocal
- module sqlalchemy.ext.selectresults
- module sqlalchemy.ext.proxy
- class AutoConnectEngine(BaseProxyEngine)
- class BaseProxyEngine(Executor)
- class ProxyEngine(BaseProxyEngine)
- module sqlalchemy.ext.orderinglist
- module sqlalchemy.ext.associationproxy
- module sqlalchemy.databases.sqlite
- Module Functions
- class DateTimeMixin(object)
- class PassiveDefault(DefaultGenerator)
- class SLBinary(Binary)
- class SLBoolean(Boolean)
- class SLChar(CHAR)
- class SLDate(DateTimeMixin,Date)
- class SLDateTime(DateTimeMixin,DateTime)
- class SLInteger(Integer)
- class SLNumeric(Numeric)
- class SLSmallInteger(SmallInteger)
- class SLString(String)
- class SLText(TEXT)
- class SLTime(DateTimeMixin,Time)
- class SQLiteCompiler(ANSICompiler)
- class SQLiteDialect(ANSIDialect)
- class SQLiteExecutionContext(DefaultExecutionContext)
- class SQLiteIdentifierPreparer(ANSIIdentifierPreparer)
- class SQLiteSchemaDropper(ANSISchemaDropper)
- class SQLiteSchemaGenerator(ANSISchemaGenerator)
- module sqlalchemy.databases.postgres
- Module Functions
- class PG1Date(Date)
- class PG1DateTime(DateTime)
- class PG1Time(Time)
- class PG2Date(Date)
- class PG2DateTime(DateTime)
- class PG2Time(Time)
- class PGBigInteger(PGInteger)
- class PGBinary(Binary)
- class PGBoolean(Boolean)
- class PGChar(CHAR)
- class PGCompiler(ANSICompiler)
- class PGDefaultRunner(ANSIDefaultRunner)
- class PGDialect(ANSIDialect)
- class PGExecutionContext(DefaultExecutionContext)
- class PGFloat(Float)
- class PGIdentifierPreparer(ANSIIdentifierPreparer)
- class PGInet(TypeEngine)
- class PGInteger(Integer)
- class PGInterval(TypeEngine)
- class PGNumeric(Numeric)
- class PGSchemaDropper(ANSISchemaDropper)
- class PGSchemaGenerator(ANSISchemaGenerator)
- class PGSmallInteger(SmallInteger)
- class PGString(String)
- class PGText(TEXT)
- module sqlalchemy.databases.mysql
- Module Functions
- class MSBigInteger(MSInteger)
- class MSBinary(_BinaryType)
- class MSBlob(_BinaryType)
- class MSBoolean(Boolean)
- class MSChar(_StringType,CHAR)
- class MSDate(Date)
- class MSDateTime(DateTime)
- class MSDecimal(MSNumeric)
- class MSDouble(MSNumeric)
- class MSEnum(MSString)
- class MSFloat(Float,_NumericType)
- class MSInteger(Integer,_NumericType)
- class MSLongBlob(MSBlob)
- class MSLongText(MSText)
- class MSMediumBlob(MSBlob)
- class MSMediumText(MSText)
- class MSNChar(_StringType,CHAR)
- class MSNVarChar(_StringType,String)
- class MSNumeric(Numeric,_NumericType)
- class MSSmallInteger(SmallInteger,_NumericType)
- class MSString(_StringType,String)
- class MSText(_StringType,TEXT)
- class MSTime(Time)
- class MSTimeStamp(TIMESTAMP)
- class MSTinyBlob(MSBlob)
- class MSTinyText(MSText)
- class MSVarBinary(_BinaryType)
- class MSYear(String)
- class MySQLCompiler(ANSICompiler)
- class MySQLDialect(ANSIDialect)
- class MySQLExecutionContext(DefaultExecutionContext)
- class MySQLIdentifierPreparer(ANSIIdentifierPreparer)
- class MySQLSchemaDropper(ANSISchemaDropper)
- class MySQLSchemaGenerator(ANSISchemaGenerator)
- class array(object)
- module sqlalchemy.databases.oracle
- Module Functions
- class OracleBinary(Binary)
- class OracleBoolean(Boolean)
- class OracleChar(CHAR)
- class OracleCompiler(ANSICompiler)
- class OracleDate(Date)
- class OracleDateTime(DateTime)
- class OracleDefaultRunner(ANSIDefaultRunner)
- class OracleDialect(ANSIDialect)
- class OracleExecutionContext(DefaultExecutionContext)
- class OracleInteger(Integer)
- class OracleNumeric(Numeric)
- class OracleRaw(Binary)
- class OracleSchemaDropper(ANSISchemaDropper)
- class OracleSchemaGenerator(ANSISchemaGenerator)
- class OracleSmallInteger(SmallInteger)
- class OracleString(String)
- class OracleText(TEXT)
- class OracleTimestamp(TIMESTAMP)
- module sqlalchemy.databases.mssql
- Module Functions
- class AdoMSNVarchar(MSNVarchar)
- class MSBinary(Binary)
- class MSBoolean(Boolean)
- class MSChar(CHAR)
- class MSDate(Date)
- class MSDateTime(DateTime)
- class MSDateTime_adodbapi(MSDateTime)
- class MSDateTime_pyodbc(MSDateTime)
- class MSDate_pymssql(MSDate)
- class MSDate_pyodbc(MSDate)
- class MSFloat(Float)
- class MSInteger(Integer)
- class MSNChar(NCHAR)
- class MSNVarchar(Unicode)
- class MSNumeric(Numeric)
- class MSSQLCompiler(ANSICompiler)
- class MSSQLDefaultRunner(ANSIDefaultRunner)
- class MSSQLDialect(ANSIDialect)
- class MSSQLDialect_adodbapi(MSSQLDialect)
- class MSSQLDialect_pymssql(MSSQLDialect)
- class MSSQLDialect_pyodbc(MSSQLDialect)
- class MSSQLExecutionContext(DefaultExecutionContext)
- class MSSQLExecutionContext_pyodbc(MSSQLExecutionContext)
- class MSSQLIdentifierPreparer(ANSIIdentifierPreparer)
- class MSSQLSchemaDropper(ANSISchemaDropper)
- class MSSQLSchemaGenerator(ANSISchemaGenerator)
- class MSSmallInteger(SmallInteger)
- class MSString(String)
- class MSText(TEXT)
- class MSTime(Time)
- class MSTimeStamp(TIMESTAMP)
- class MSTinyInteger(Integer)
- module sqlalchemy.databases.firebird
- Module Functions
- class FBBinary(Binary)
- class FBBoolean(Boolean)
- class FBChar(CHAR)
- class FBCompiler(ANSICompiler)
- class FBDate(DateTime)
- class FBDateTime(DateTime)
- class FBDefaultRunner(ANSIDefaultRunner)
- class FBDialect(ANSIDialect)
- class FBExecutionContext(DefaultExecutionContext)
- class FBIdentifierPreparer(ANSIIdentifierPreparer)
- class FBInteger(Integer)
- class FBNumeric(Numeric)
- class FBSchemaDropper(ANSISchemaDropper)
- class FBSchemaGenerator(ANSISchemaGenerator)
- class FBSmallInteger(SmallInteger)
- class FBString(String)
- class FBText(TEXT)
This tutorial provides a relatively simple walking tour through the basic concepts of SQLAlchemy. You may wish to skip it and dive into the main manual which is more reference-oriented. The examples in this tutorial comprise a fully working interactive Python session, and are guaranteed to be functioning courtesy of doctest.
Installation
Installing SQLAlchemy
Installing SQLAlchemy from scratch is most easily achieved with setuptools. (setuptools installation). Just run this from the command-line:
# easy_install SQLAlchemy
This command will download the latest version of SQLAlchemy from the Python Cheese Shop and install it to your system.
Otherwise, you can install from the distribution using the setup.py script:
# python setup.py install
back to section top
Installing a Database API
SQLAlchemy is designed to operate with a DBAPI implementation built for a particular database, and includes support for the most popular databases. If you have one of the supported DBAPI implementations, you can proceed to the following section. Otherwise SQLite is an easy-to-use database to get started with, which works with plain files or in-memory databases.
SQLite is included with Python 2.5 and greater.
If you are working with Python 2.3 or 2.4, SQLite and the Python API for SQLite can be installed from the following packages:
- pysqlite - Python interface for SQLite
- SQLite library
Note that the SQLite library download is not required with Windows, as the Windows Pysqlite library already includes it linked in. Pysqlite and SQLite can also be installed on Linux or FreeBSD via pre-made packages or from sources.
back to section topGetting Started
Checking the Version
Note: This tutorial is oriented towards version 0.3.10 of SQLAlchemy. It will *not* work with versions earlier than 0.3.9. Check the version of SQLAlchemy you have installed via:
>>> import sqlalchemy >>> sqlalchemy.__version__ 0.3.10
Imports
To start connecting to databases and begin issuing queries, we want to import the base of SQLAlchemy's functionality, which is provided under the module name of sqlalchemy. For the purposes of this tutorial, we will import its full list of symbols into our own local namespace.
>>> from sqlalchemy import *
Note that importing using the * operator pulls all the names from sqlalchemy into the local module namespace, which in a real application can produce name conflicts. Therefore its recommended in practice to either import the individual symbols desired (i.e. from sqlalchemy import Table, Column) or to import under a distinct namespace (i.e. import sqlalchemy as sa).
Connecting to the Database
After our imports, the next thing we need is a handle to the desired database, represented by an Engine object. This object handles the business of managing connections and dealing with the specifics of a particular database. Below, we will make a SQLite connection to a file-based database called "tutorial.db".
>>> db = create_engine('sqlite:///tutorial.db')
Technically, the above statement did not make an actual connection to the sqlite database just yet. As soon as we begine working with the engine, it will start creating connections. In the case of SQLite, the tutorial.db file will actually be created at the moment it is first used, if the file does not exist already.
For full information on creating database engines, including those for SQLite and others, see Database Engines.
back to section topSQLAlchemy is Two Libraries in One
Now that the basics of installing SQLAlchemy and connecting to our database are established, we can start getting in to actually doing something. But first, a little bit of explanation is required.
A central concept of SQLAlchemy is that it actually contains two distinct areas of functionality, one of which builds upon the other. One is a SQL Construction Language and the other is an Object Relational Mapper ("ORM" for short). The SQL construction language allows you to construct objects called ClauseElements which represent SQL expressions. These ClauseElements can then be executed against any database, where they are compiled into strings that are appropriate for the target database, and return an object called a ResultProxy, which is essentially a result set object that acts very much like a deluxe version of the dbapi cursor object.
The Object Relational Mapper (ORM) is a set of tools completely distinct from the SQL Construction Language which serve the purpose of mapping Python object instances into database rows, providing a rich selection interface with which to retrieve instances from tables as well as a comprehensive solution to persisting changes on those instances back into the database. When working with the ORM, its underlying workings as well as its public API make extensive use of the SQL Construction Language, however the general theory of operation is slightly different. Instead of working with database rows directly, you work with your own user-defined classes and object instances. Additionally, the method of issuing queries to the database is different, as the ORM handles the job of generating most of the SQL required, and instead requires more information about what kind of class instances you'd like to load and where you'd like to put them.
Where SA is somewhat unique, more powerful, and slightly more complicated is that the two areas of functionality can be mixed together in many ways. A key strategy to working with SA effectively is to have a solid awareness of these two distinct toolsets, and which concepts of SA belong to each - even some publications have confused the SQL Construction Language with the ORM. The key difference between the two is that when you're working with cursor-like result sets its the SQL Construction Language, and when working with collections of your own class instances its the Object Relational Mapper.
This tutorial will first focus on the basic configuration that is common to using both the SQL Construction Language as well as the ORM, which is to declare information about your database called table metadata. This will be followed by some constructed SQL examples, and then into usage of the ORM utilizing the same data we established in the SQL construction examples.
back to section topWorking with Database Objects
Defining Metadata, Binding to Engines
Configuring SQLAlchemy for your database consists of creating objects called Tables, each of which represent an actual table in the database. A collection of Table objects resides in a MetaData object which is essentially a table collection. We will create a MetaData and connect it to our Engine (connecting a schema object to an Engine is called binding):
>>> metadata = MetaData() >>> metadata.bind = db
An equivalent operation is to create the MetaData object directly with the Engine:
>>> metadata = MetaData(db)
Now, when we tell "metadata" about the tables in our database, we can issue CREATE statements for those tables, as well as execute SQL statements derived from them, without needing to open or close any connections; that will be all done automatically.
Note that SQLALchemy allows us to use explicit connection objects for everything, if we wanted to, and there are reasons why you might want to do this. But for the purposes of this tutorial, using bind removes the need for us to deal with explicit connections.
Creating a Table
With metadata as our established home for tables, lets make a Table for it:
>>> users_table = Table('users', metadata, ... Column('user_id', Integer, primary_key=True), ... Column('user_name', String(40)), ... Column('password', String(15)) ... )
As you might have guessed, we have just defined a table named users which has three columns: user_id (which is a primary key column), user_name and password. Currently it is just an object that doesn't necessarily correspond to an existing table in our database. To actually create the table, we use the create() method. To make it interesting, we will have SQLAlchemy echo the SQL statements it sends to the database, by setting the echo flag on the Engine associated with our MetaData:
>>> metadata.bind.echo = True >>> users_table.create() CREATE TABLE users ( user_id INTEGER NOT NULL, user_name VARCHAR(40), password VARCHAR(15), PRIMARY KEY (user_id) ) ...
Alternatively, the users table might already exist (such as, if you're running examples from this tutorial for the second time), in which case you can just skip the create() method call. You can even skip defining the individual columns in the users table and ask SQLAlchemy to load its definition from the database:
>>> users_table = Table('users', metadata, autoload=True) >>> list(users_table.columns)[0].name 'user_id'
Loading a table's columns from the database is called reflection. Documentation on table metadata, including reflection, is available in Database Meta Data.
back to section topInserting Rows
Inserting is achieved via the insert() method, which defines a clause object (known as a ClauseElement) representing an INSERT statement:
>>> i = users_table.insert() >>> i <sqlalchemy.sql._Insert object at 0x...> >>> # the string form of the Insert object is a generic SQL representation >>> print i INSERT INTO users (user_id, user_name, password) VALUES (?, ?, ?)
Since we created this insert statement object from the users table which is bound to our Engine, the statement itself is also bound to the Engine, and supports executing itself. The execute() method of the clause object will compile the object into a string according to the underlying dialect of the Engine to which the statement is bound, and will then execute the resulting statement.
>>> # insert a single row >>> i.execute(user_name='Mary', password='secure') INSERT INTO users (user_name, password) VALUES (?, ?)
