pg8000

About

pg8000 is a Pure-Python interface to the PostgreSQL database engine. It is one of many PostgreSQL interfaces for the Python programming language. pg8000 is somewhat distinctive in that it is written entirely in Python and does not rely on any external libraries (such as a compiled python module, or PostgreSQL's libpq library).

pg8000's name comes from the belief that it is probably about the 8000th PostgreSQL interface for Python.

pg8000 supports the standard DB-API 2.0 as documented in PEP-249 (as of pg8000 v1.03).

Download Latest

The latest release of pg8000 is version 1.03, released on March 9th, 2008.

Documentation

pg8000's API documentation is produced by PythonDoc. The HTML output is generated from documentation integrated with the pg8000 source code.

Source Code Repository

pg8000 is distributed under the terms of a modified BSD license. The complete source code and history is available through a Mercurial for anyone who is interested, at http://hg.pybrary.net/pg8000/. There is also a Python 3.0 compatible branch available at http://hg.pybrary.net/pg8000-py3/.

Example (pg8000 interface)

import pg8000

db = pg8000.Connection(host='dbserver', user='dbuser')

# the simplest direct execution of SQL...
db.execute("SELECT col1, col2 FROM table")
for row in db.iterate_dict():
    print row['col1'], row['col2']

# using multiple cursors...
cur1 = pg8000.Cursor(db)
cur2 = pg8000.Cursor(db)

cur1.execute("SELECT book_id FROM book")
for row in cur1.iterate_tuple():
    book_id = row[0]
    cur2.execute("SELECT reader_id, reader_name FROM reader WHERE book_id = $1", book_id)
    for row2 in cur2.iterate_tuple():
        print book_id, row2[0], row2[1]

# using a prepared statement...
stmt = pg8000.PreparedStatement(db, "INSERT INTO book (book_id, book_name) VALUES ($1, $2)")
stmt.execute(1, "The Wide World of Cats")
stmt.execute(2, "The Small World of Dogs")
stmt.execute(3, "The Microscopic World of Humans")

Changelog

Version 1.03, 2008-03-09

Version 1.02, 2007-03-13

Version 1.01, 2007-03-09

Version 1.00, 2007-03-08