[DB-SIG] Why so many Python drivers for PostgreSQL?

Federico Di Gregorio fog at initd.org
Tue Jan 19 08:23:01 CET 2010


On 19/01/2010 01:24, Christoph Zwerschke wrote:
> Bob Kline wrote:
>> Are the deficiencies in each of the drivers so serious that so many
>> programmers are driven to roll their own? Or are these the
>> outgrowths of ambitious student projects?
> 
> This has historical reasons. Python and PostgreSQL are both around for a
> long time and have evolved quite a bit, and there were two DBAPI
> releases. These developments prompted people to create new drivers using
> the new standards, but some of the older projects were not given up and
> modernized as well. PyGreSQL started even before DBAPI, but is still
> maintained and quite stable; it provides the old interface in addition
> to a newer DBAPI 2 module. pyPgSQL has the special feature of returning
> rows as dictionary. Psycopg2 is more modern, sophisticated (built-in
> connection pooling) and can be considered the mainstream. Then of
> course, there are also drivers for platforms different from traditional
> CPython, such as JDBC, .NET, pure Python drivers etc.

In fact the main feature of psycopg is not connection pooling (just an
extra to show the possibility to subclass connection and cursor objects)
but type adaptation that let you specify how to convert any Python type
to PostgreSQL and back.

If you want a row as a dictionary you just need to subclass cursor and
pass the new type to the connection and voilà!, your new cursor can
override the fetchXXX methods and build dicts instead of tuples (in fact
this example is included in the psycopg2.extras module.)

federico

-- 
Federico Di Gregorio                                       fog at initd.org
  Those who do not study Lisp are doomed to reimplement it. Poorly.
                                     -- from Karl M. Hegbloom .signature

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/db-sig/attachments/20100119/a201da81/attachment.pgp>


More information about the DB-SIG mailing list