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')
db.execute("SELECT col1, col2 FROM table")
for row in db.iterate_dict():
print row['col1'], row['col2']
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]
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
- Separate pg8000.py into multiple python modules within the pg8000 package. There should be no need for a client to change how pg8000 is imported.
- Fix bug in row_description property when query has not been completed.
- Fix bug in fetchmany dbapi method that did not properly deal with the end of result sets.
- Add close methods to DB connections.
- Add callback event handlers for server notices, notifications, and runtime configuration changes.
- Add boolean type output.
- Add date, time, and timestamp types in/out.
- Add recognition of "SQL_ASCII" client encoding, which maps to Python's "ascii" encoding.
- Add types.Interval class to represent PostgreSQL's interval data type, and appropriate wire send/receive methods.
- Remove unused type conversion methods.
Version 1.02, 2007-03-13
- Add complete DB-API 2.0 interface.
- Add basic SSL support via ssl connect bool.
- Rewrite pg8000_test.py to use Python's unittest library.
- Add bytea type support.
- Add support for parameter output types: NULL value, timestamp value, python long value.
- Add support for input parameter type oid.
Version 1.01, 2007-03-09
- Add support for writing floats and decimal objs up to PG backend.
- Add new error handling code and tests to make sure connection can recover
from a database error.
- Fixed bug where timestamp types were not always returned in the same binary
format from the PG backend. Text format is now being used to send
timestamps.
- Fixed bug where large packets from the server were not being
read fully, due to socket.read not always returning full read size
requested. It was a lazy-coding bug.
- Added locks to make most of the library thread-safe.
- Added UNIX socket support.
Version 1.00, 2007-03-08
- First public release. Although fully functional, this release
is mostly lacking in production testing and in type support.
Basically, more exposure to real-life usage situations and
different PostgreSQL versions is required to see how well it
works.