Postgresql - Preferred Python Library

Matt Goodall matt at
Fri Sep 10 10:20:38 CEST 2004

On Fri, 2004-09-10 at 06:28 +0000, Harald Massa wrote:
> > I have noticed that there are a numbe rof client libraries for
> > connecting to Postgres.
> > Can anyone tell me what is the recommended Python library for database
> > connections

I've just started experimenting with psycopg2
( and it's looking good.

As far as I know, psycopg2 is the only DB-API 2.0 implementation for
PostgreSQL that uses Python 2.3's datetime types by default. In fact, I
think it supports *all* native Python types that have a corresponding
database type. For me, this makes a big difference. I find moving data
from RDBMS to application to RDBMS quite irritating and it just makes
matters worse when I have to convert between data types too.

Assuming I don't come across any serious issues, I will be using
psycopg2 from now on.

(I also use dateutil, <>, which
extends datetime with lots of useful stuff. So useful, it should
probably be part of the standard library.)

> I recommend pyPgSQL -
> it gives you high level (DBAPI2) and if you wish also low level access 
> (libpq)
> Twisted seems to use it, to.

Twisted's adbapi will use any DB-API 2.0 implementation with a
threadsafety level of 1 or greater. I have tested one application with
pypgsql, pygresql, psycopg and psycopg2. Twisted was happy with all of
them, although differences in how python and column types are handled
means the application code is not necessarily portable by default.

See <> for
more information on using an RDMBS from a Twisted application.

Cheers, Matt

    /  \__     Matt Goodall, Pollenation Internet Ltd
    \__/  \    w:
  __/  \__/    e: matt at
 /  \__/  \    t: +44 (0)113 2252500
 \__/  \__/
 /  \          Any views expressed are my own and do not necessarily
 \__/          reflect the views of my employer.

More information about the Python-list mailing list