Database Programming

Python talks to databases through the DB-API, a standard interface defined in PEP 249. This section has everything from getting-started guides to cheat sheets to opinionated critiques of the API itself. You will also find pages for specific database engines and ORMs. Some of the version information here is dated, but the conceptual material on DB-API usage holds up well.

Getting Started

  • DatabaseProgramming – starting point for learning about databases in Python, covering relational databases, the DB-API, and ORMs

  • DatabaseInterfaces – list of available Python database interface modules, organized by database engine

  • DatabaseBooks – recommended books on database concepts and Python database programming

  • DatabaseBof – notes from a birds-of-a-feather meeting on Python database capabilities

  • DatabaseTemplate – blank template for documenting a database interface

The DB-API

  • DbApi3 – discussion topics for a possible DB-API 3.0 specification

  • DbApi3 subpages – related discussions and proposals for DB-API 3

  • DbApiCheatSheet – quick syntax reference comparing DB-API usage across PostgreSQL, SQLite, MySQL, Oracle, and ODBC

  • DbApiFaq – frequently asked questions from the DB-SIG mailing list, including parameter passing and cursor usage

  • DbApiModuleComparison – side-by-side feature comparison table of DB-API modules

  • DbApiSucks – frank criticism of DB-API design decisions, particularly around cursor semantics

Database Engines

  • SQLite – the embedded database bundled with Python’s standard library

  • PostgreSQL – PostgreSQL interface information

  • MySQL – MySQL interface information

  • Oracle – Oracle database interface information

  • SQL Server – Microsoft SQL Server connectivity

  • ADO – Microsoft’s ActiveX Data Objects, a high-level database interface on Windows

ORMs and Tools

  • SQLAlchemy – the Python SQL toolkit and ORM

  • SQL – overview of Python’s SQL database support and pointers to interface modules

  • SQLPython – a Python-based alternative to Oracle’s SQL*Plus command-line tool