Psycopg – PostgreSQL database adapter for Python — Psycopg v2.0.14 documentation

### Navigation

- index
- modules |
- next |
- Psycopg v2.0.14 documentation »

# Psycopg – PostgreSQL database adapter for Python

Psycopg is a PostgreSQL database adapter for the Python programming language. Its main advantages are that it supports the full Python DB API 2.0 and it is thread safe (threads can share the connections). It was designed for heavily multi-threaded applications that create and destroy lots of cursors and make a conspicuous number of concurrent `INSERT`s or `UPDATE`s. The psycopg distribution includes ZPsycopgDA, a Zope Database Adapter.

Psycopg 2 is an almost complete rewrite of the Psycopg 1.1.x branch. Psycopg 2 features complete libpq v3 protocol, `COPY TO/COPY FROM` and full object adaptation for all basic Python types: strings (including unicode), ints, longs, floats, buffers (binary objects), booleans, mx.DateTime and builtin datetime types. It also supports unicode queries and Python lists mapped to PostgreSQL arrays.

Contents

- Basic module usage
  - Passing parameters to SQL queries
  - Adaptation of Python values to SQL types
  - Transactions control
  - Server side cursors
  - Thread safety
  - Using COPY TO and COPY FROM
  - Access to PostgreSQL large objects
- The `psycopg2` module content
  - Exceptions
  - Type Objects and Constructors
- The `connection` class
- The `cursor` class
- More advanced topics
  - Connection and cursor factories
  - Adapting new Python types to SQL syntax
  - Type casting of SQL types into Python objects
  - Asynchronous notifications
  - Asynchronous queries
- `psycopg2.extensions` – Extensions to the DB API
  - SQL adaptation protocol objects
  - Database types casting functions
  - Additional exceptions
  - Isolation level constants
  - Transaction status constants
  - Connection status constants
  - Additional database types
- `psycopg2.tz` – `tzinfo` implementations for Psycopg 2
- `psycopg2.pool` – Connections pooling
- `psycopg2.extras` – Miscellaneous goodies for Psycopg 2
  - Dictionary-like cursor
  - Logging cursor
  - UUID data type
  - `inet` data type
  - Fractional time zones
- `psycopg2.errorcodes` – Error codes defined by PostgreSQL
- Frequently Asked Questions

Indices and tables

- Index
- Search Page

### Navigation

- index
- modules |
- next |
- Psycopg v2.0.14 documentation »