[DB-SIG] [ANN] pyPgSQL 2.1 released

Kevin Jacobs jacobs@penguin.theopalgroup.com
Fri, 7 Jun 2002 07:42:35 -0400 (EDT)


On 6 Jun 2002, Joseph Wilhelm wrote:
> On Thu, 2002-06-06 at 06:30, Andy Dustman wrote:
> <snip> 
> > I'm curious... There are at least two actively maintained PostgreSQL
> > interfaces (three if you count the one that comes with PostgreSQL). I've
> > personally used psycopg a bit lately. What are the advantages and
> > disadvantages of the various interfaces?
> <snip>
> 
> Another bit of curiosity... do either of these interfaces support
> dictionary results? I'm currently using the 'pg' module provided with
> the PostgreSQL distribution primarily for the fact that I have need of
> dictionary results, and pg gladly supplies them. However, if one of
> these is "better", and provides me with dicts, I would love to give it a
> shot.

If you are using Python 2.2, I have a new open souce module you may want to
try out.  It uses some of the new Python 2.2 features to produce
light-weight objects that have most of the functionality of tuples _and_
dictionaries, but are less expensive than dictionaries.  i.e., you can
do the following:

  row[0]      # access by index
  row[3:7]    # access by slice
  row['Foo']  # access by item interface
  row.Foo     # access by attribute interface

Field names accessors can also be made case-insensitive.

Here are a few benchmarks that measure the time and memory required to
create 200,000 result objects of various types with 11 integer values:

                                     Time     Approx.
                             SIZE    (sec)  Bytes/row
                         --------   ------  ---------
            baseline:     4,744KB     0.56        -
               tuple:    18,948KB     2.49       73
                dict:       117MB    13.50      589
  Pure Python db_row:    18,960KB    17.23       73
            C db_row:    18,924KB     4.85       73


For more information take a look at http://opensource.theopalgroup.com

-Kevin

--
Kevin Jacobs
The OPAL Group - Enterprise Systems Architect
Voice: (216) 986-0710 x 19         E-mail: jacobs@theopalgroup.com
Fax:   (216) 986-0714              WWW:    http://www.theopalgroup.com