[Twisted-Python] using Twisted with postgresql

Manlio Perillo manlio_perillo at libero.it
Tue Oct 16 06:07:07 EDT 2007

Doris Lam ha scritto:
> Hi,
> I'm new to Twisted and is currently looking for a way to asynchronously 
> do queries to a postgres database. From what I've seen it looks like 
> there's a project called pgasync (http://jamwt.com/pgasync/) that does 
> this, or I can use Twisted's adbapi and some other synchronous module. 

Some time ago, I have refactored the pgasync implementation in pglib:

It offers an API for almost all the functionality of the Posgres protocol.
The only thing missing is a connection pool manager, and support for 
prepared queries.

> I'm wondering if anyone has used pgasync and how it compares to using 
> adbapi and threads? From the pgasync site it seems the last update was 
> in 2005, so I'm not sure if anyone's still maintaining it. If using 
> adbapi's better, can I get some suggestions as to which postgres module 
> I should use? So far I've seen pyPgSQL and psychopg that're both DB API 
> 2 compliant. Any help will be appreciated!

A pure asynchronous implementation has better performance, in theory, 
since you don't need to use thread locks.

Moreover, pglib can be very useful, as an example, if you want to 
"consume" each row at a time, or if you want to listen for database 

However using libpq has many advantages.
You can also use the asynchronous interface that psycopg2 implements:

However you *need* a good connection pool manager for asynchronous 
connections, and, as far as I know, no one has yet written such a thing.

I'm interested in this topic, since I'm writing a WSGI implementation 
for Nginx and it, like Twisted, is asynchronous (and *without* threads 

Regards  Manlio Perillo

More information about the Twisted-Python mailing list