pgasync is a Twisted-based PostgreSQL client library which fully conforms to the DB API 2.0 specification, and provides adbapi compatibility. It's designed to run quickly and scale well. It provides connection pooling and persistence, database types, and safe conversions.

For the uninitiated: If you're into Twisted, this project is potentially very interesting to you. If you don't use Twisted, or have never heard of it, you probably won't care.





pgasync uses distutils. To install, simply execute the following as root in the unpacked distribution directory:

# python install

This will usually "just work", but there are two places that you may run into problems here: first, you may encounter a compilation error on cache.c. If that's the case, you can try to use Pyrex to regenerate cache.c from the cache.pyx file in pgasync/. See the README for more detail.

The other problem that may occur is that compilation of convert.c fails or gives warnings about "implicit declaration" of the funcions htons and/or htonl. If this does happen, I'd appreciate an email about what platform/os you're on so I can track down the proper include file. Linux and FreeBSD should work.


from pgasync import ConnectionPool
pool = ConnectionPool("pgasync",

# simple query usage where you don't care about the cursor 
# (description, rowcount, etc)

def printUsers(results):
	for row in results:
		# do something with row

pool.runQuery("select * from users where uid = %s",13).addCallback(printUsers)

# simple, one-pass operation 
pool.runOperation("insert into users values (%s,%s,%s)",(1,2,3))

# transactions, more complex db-api style things
connection = pool.connect()

cursor = connection.cursor()
cursor.execute("delete from users where uid = %(uid)s", {"uid" : 13})
cursor.execute("update users set status = 'confirmed' where uid = %s", 13)
cursor.execute("select * from users").addCallback(printUsers)

# pool control
pool.min = 3
pool.max = 12  
print pool.running


If you observe these notes, you'll have a good understanding of the couple of places that it differentiates from standard sync db api or adbapi libraries, the bit of special treatment/thought it needs.


Public subversion read access is available:

svn co svn://


pgasync was written by Jamie Turner. I'd appreciate hearing about any bugs or suggestions.

I'm often on #twisted.web on during working hours, pacific time. You can subscribe to the mailing list using the address below.

<this project>-subscribe at j a mwt dot (com)

Omit '-subscribe' to send the list a message. Mailing list archives.