SQLAlchemy Example Projects and Code

SQLAlchemy is a well-regarded database toolkit and object-relational mapper (ORM) implementation written in Python. SQLAlchemy provides a generalized interface for creating and executing database-agnostic code without needing to write SQL statements. SQLAlchemy logo.

Code Examples Sorted by SQLAlchemy Package

Specific examples are shown on the following individual pages, organized by classes and functions provided by SQLAlchemy, that are typically used when building your own applications.

SQLAlchemy: Extensions, Plug-ins and Related Libraries & Example Projects and Code

sqlalchemy.dialects mssql, mysql, oracle, postgresql, sqlite

sqlalchemy.dialects.mysql pymysql

sqlalchemy.dialects.postgresql ARRAY, BIGINT, BIT, DOUBLE_PRECISION, ExcludeConstraint, INTEGER, JSON, TSVECTOR, array, json, pypostgresql

sqlalchemy.dialects.postgresql.base PGTypeCompiler

sqlalchemy.dialects.postgresql.psycopg2 PGDialect_psycopg2

sqlalchemy.dialects.sqlite pysqlite

sqlalchemy.engine Connection, Engine, create_engine, default, url

sqlalchemy.engine.default DefaultDialect

sqlalchemy.engine.interfaces ExecutionContext

sqlalchemy.engine.result ResultMetaData, RowProxy

sqlalchemy.engine.strategies EngineStrategy, MockEngineStrategy

sqlalchemy.engine.url make_url

sqlalchemy.events SchemaEventTarget

sqlalchemy.exc ArgumentError, DataError, IntegrityError, InvalidRequestError, NoInspectionAvailable, OperationalError, ProgrammingError

sqlalchemy.ext compiler

sqlalchemy.ext.automap automap_base

sqlalchemy.ext.compiler compiles

sqlalchemy.ext.declarative DeclarativeMeta, declarative_base

sqlalchemy.ext.hybrid HYBRID_PROPERTY, hybrid_property

sqlalchemy.ext.mutable Mutable

sqlalchemy.inspection inspect

sqlalchemy.orm ColumnProperty, CompositeProperty, Mapper, Session, SynonymProperty, attributes, backref, class_mapper, column_property, composite, interfaces, mapper, mapperlib, object_mapper, object_session, relationship, session, sessionmaker, strategies

sqlalchemy.orm.attributes InstrumentedAttribute

sqlalchemy.orm.collections InstrumentedList

sqlalchemy.orm.exc NoResultFound, UnmappedClassError, UnmappedInstanceError

sqlalchemy.orm.interfaces MapperProperty, PropComparator

sqlalchemy.orm.properties ColumnProperty, RelationshipProperty

sqlalchemy.orm.query Query, QueryContext

sqlalchemy.orm.session Session, object_session

sqlalchemy.orm.util AliasedInsp

sqlalchemy.pool NullPool, StaticPool

sqlalchemy.schema CheckConstraint, Column, CreateIndex, DDLElement, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, Table

sqlalchemy.sql ClauseElement, Select, column, expression, functions, operators, schema, select, sqltypes, table

sqlalchemy.sql.elements ColumnElement, Label

sqlalchemy.sql.expression ClauseElement, ColumnClause, ColumnElement, Executable, FunctionElement, UnaryExpression

sqlalchemy.sql.functions FunctionElement, GenericFunction

sqlalchemy.sql.naming conv

sqlalchemy.sql.schema Column, SchemaItem

sqlalchemy.sql.sqltypes NULLTYPE, NullType

sqlalchemy.sql.util ClauseAdapter

sqlalchemy.sql.visitors traverse

sqlalchemy.types BOOLEAN, Boolean, Enum, INTEGER, Integer, NULLTYPE, NullType, String, TypeEngine, UserDefinedType, to_instance

sqlalchemy.util OrderedDict, OrderedSet, set_creation_order, topological

sqlalchemy.util.langhelpers symbol

Example Open Source Projects

The following open source projects can serve as example code for you as you build your own applications with SQLAlchemy.

databases

databases (project homepage and PyPI page provides asyncio support with an SQLALchemy Core interface for common relational databases such as MySQL, PostgreSQL and SQLite. This is handy for integrating with asynchronous I/O web frameworks like Sanic. The project is open sourced under the BSD 3-Clause "New" or "Revised" License.

sandman2

sandman2 (project documentation and PyPI package information) is a code library for automatically generating RESTful APIs from existing database schemas. This approach is handy for solving straightforward situations where you want to put an abstraction layer between one or more applications and your relational database to prevent or reduce direct database access.

The sandman2 project is provided under the Apache License 2.0.

Sponsored By

Sentry logo

Software errors are inevitable. Chaos is not. Try Sentry for free.

1. Introduction 2. Development Environments 3. Data 4. Web Development 5. Deployment 6. DevOps Changelog What Full Stack Means About the Author Future Directions Page Statuses SQLAlchemy ExtensionsSQLAlchemy Example CodeSQLAlchemy Modelssqlalchemy.dialects mssqlsqlalchemy.dialects mysqlsqlalchemy.dialects oraclesqlalchemy.dialects postgresqlsqlalchemy.schema DDLsqlalchemy.dialects sqlitesqlalchemy.sql.expression Functionsqlalchemy.dialects.mysql pymysqlsqlalchemy.dialects.postgresql ARRAYsqlalchemy.dialects.postgresql BIGINTsqlalchemy.dialects.postgresql BITsqlalchemy.dialects.postgresql DOUBLE_PRECISIONsqlalchemy.dialects.postgresql ExcludeConstraintsqlalchemy.dialects.postgresql INTEGERsqlalchemy.dialects.postgresql JSONsqlalchemy.dialects.postgresql TSVECTORsqlalchemy.dialects.postgresql pypostgresqlsqlalchemy.dialects.postgresql.base PGTypeCompilersqlalchemy.dialects.postgresql.psycopg2 PGDialect_psycopg2sqlalchemy.dialects.sqlite pysqlitesqlalchemy.engine Connectionsqlalchemy.engine Enginesqlalchemy.engine create_enginesqlalchemy.engine defaultsqlalchemy.engine urlsqlalchemy.engine.default DefaultDialectsqlalchemy.engine.interfaces ExecutionContextsqlalchemy.engine.result ResultMetaDatasqlalchemy.engine.result RowProxysqlalchemy.engine.strategies EngineStrategysqlalchemy.engine.strategies MockEngineStrategysqlalchemy.engine.url make_urlsqlalchemy.events SchemaEventTargetsqlalchemy.exc ArgumentErrorsqlalchemy.exc DataErrorsqlalchemy.exc IntegrityErrorsqlalchemy.exc InvalidRequestErrorsqlalchemy.exc NoInspectionAvailablesqlalchemy.exc OperationalErrorsqlalchemy.exc ProgrammingErrorsqlalchemy.ext compilersqlalchemy.ext.automap automap_basesqlalchemy.ext.compiler compilessqlalchemy.ext.declarative DeclarativeMetasqlalchemy.ext.declarative declarative_basesqlalchemy.ext.hybrid hybrid_propertysqlalchemy.ext.mutable Mutablesqlalchemy.inspection inspectsqlalchemy.orm ColumnPropertysqlalchemy.orm CompositePropertysqlalchemy.orm SynonymPropertysqlalchemy.orm attributessqlalchemy.orm backrefsqlalchemy.orm class_mappersqlalchemy.orm column_propertysqlalchemy.orm compositesqlalchemy.orm interfacessqlalchemy.orm mappersqlalchemy.orm mapperlibsqlalchemy.orm object_mappersqlalchemy.orm object_sessionsqlalchemy.orm relationshipsqlalchemy.orm sessionsqlalchemy.orm sessionmakersqlalchemy.orm strategiessqlalchemy.orm.attributes InstrumentedAttributesqlalchemy.orm.collections InstrumentedListsqlalchemy.orm.exc NoResultFoundsqlalchemy.orm.exc UnmappedClassErrorsqlalchemy.orm.exc UnmappedInstanceErrorsqlalchemy.orm.interfaces MapperPropertysqlalchemy.orm.interfaces PropComparatorsqlalchemy.orm.properties ColumnPropertysqlalchemy.orm.properties RelationshipPropertysqlalchemy.orm.query Querysqlalchemy.orm.query QueryContextsqlalchemy.orm.session Sessionsqlalchemy.orm.session object_sessionsqlalchemy.orm.util AliasedInspsqlalchemy.pool NullPoolsqlalchemy.pool StaticPoolsqlalchemy.schema CheckConstraintsqlalchemy.schema Columnsqlalchemy.schema CreateIndexsqlalchemy.schema DDLElementsqlalchemy.schema ForeignKeysqlalchemy.schema ForeignKeyConstraintsqlalchemy.schema PrimaryKeyConstraintsqlalchemy.schema Tablesqlalchemy.sql ClauseElementsqlalchemy.sql columnsqlalchemy.sql expressionsqlalchemy.sql functionssqlalchemy.sql operatorssqlalchemy.sql schemasqlalchemy.sql selectsqlalchemy.sql sqltypessqlalchemy.sql tablesqlalchemy.sql.elements ColumnElementsqlalchemy.sql.elements Labelsqlalchemy.sql.expression ClauseElementsqlalchemy.sql.expression ColumnClausesqlalchemy.sql.expression ColumnElementsqlalchemy.sql.expression Executablesqlalchemy.sql.expression FunctionElementsqlalchemy.sql.expression UnaryExpressionsqlalchemy.sql.functions FunctionElementsqlalchemy.sql.functions GenericFunctionsqlalchemy.sql.naming convsqlalchemy.sql.schema Columnsqlalchemy.sql.schema SchemaItemsqlalchemy.sql.sqltypes NullTypesqlalchemy.sql.util ClauseAdaptersqlalchemy.sql.visitors traversesqlalchemy.types Booleansqlalchemy.types Enumsqlalchemy.types Integersqlalchemy.types NULLTYPEsqlalchemy.types Stringsqlalchemy.types TypeEnginesqlalchemy.types UserDefinedTypesqlalchemy.types to_instancesqlalchemy.util OrderedDictsqlalchemy.util OrderedSetsqlalchemy.util set_creation_ordersqlalchemy.util topologicalsqlalchemy.util.langhelpers symbol ...or view the full table of contents.

Full Stack Python

Full Stack Python is an open book that explains concepts in plain language and provides helpful resources for those topics.
Updates via Twitter & Facebook.

Matt Makai 2012-2020