[DB-SIG] Database Abstraction in Python

James Gardner james at pythonweb.org
Sat Apr 16 14:03:10 CEST 2005


Hi Chris

> Well, feel free to sauté my own words and feed them to me :) A good 
> test would be to start porting it to a few more database 
> implementations. Oracle or some ODBC-based connection would be great, 
> but I don't have access to that. I can try for PostgreSQL if you like 
> (via pyPgSQL or psycopg) if you like. Does it come with a bunch of 
> unit tests ?

:-)

I used to support Gadfly and Marc-Andre's ODBC driver too but Gadfly 
didn't support NULLs and ODBC wasn't open source so I dropped them both. 
Since the code worked with them both a few releases ago I'm fairly 
confident that it should be easy to implement drivers for ODBC and 
indeed most SQL databases, certainly PostgreSQL. There is also a driver 
mechanism in the pure Python implementation to allow data to be stored 
in different formats, I've currently only implemented a DBM driver but 
at one point also had a CSV driver too so the whole system is fairly 
extensible.

If you are keen to implement a PostgreSQL driver that would be 
fantastic.. you just derive from database.drivers.base, use 
database.drivers.mysql as an example. There are five unit tests but I 
haven't distributed them yet. Here is a zip of the CVS tree with the 
tests if it is helpful: http://pythonweb.org/projects/pdbc/PDBC.zip I'll 
package up a proper release in the next few weeks and provide some 
better documentation. Did you notice the SQL console program which works 
like the MySQL prompt but for all supported databases in portable mode?

More generally, do people feel this is a useful piece of software? Since 
the same API is used to access all underlying DB-API 2.0 drivers, this 
could be a useful way of distributing all the DB-API drivers in one 
package. If people wanted to implement drivers for the databases they 
use we could implement a feasible database abstraction layer that was 
genuinely portable when used in portable mode and provided full access 
to the underlying database in direct mode. Would this not form a useful 
basis for a DB-API 3.0?

James



More information about the DB-SIG mailing list