[DB-SIG] perl-DBI like module for Python?

M.-A. Lemburg mal at egenix.com
Tue May 25 17:05:34 EDT 2004

Mihai Ibanescu wrote:
> Hello,
> I am not sure if it was mentioned before on this list.
> Is there a module that does what the perl DBI module does?
> What I mean by that is: a top-level module that exposes the API defined in the
> DB API document, but with the ability to change backend drivers on the fly.
> Example: I have my application running against Postgres. I have to be able to
> port it to Oracle too. Unfortunately, code that tries to catch
> DatabaseException will have to look for the cx_Oracle DatabaseException, not
> for the postgres one.
> This would be easily solved if a DBI module would provide the base classes
> (for things like Database, Cursor, DatabaseException etc.) that the code could
> use, and a connect function that could specify the database driver to use
> (postgres, cx_Oracle etc). Drivers would inherit their classes from this
> top-level module. 
> jdbc/odbc do the same thing.
> Is there such a thing out there?

If you're looking for a true DBI kind of approach:

* works with Oracle, MS SQL Server, SAP DB, PostgreSQL, etc. etc.
* same API for all of these
* same API on Windows, Unix, *BSD, AIX, etc. etc.
* supported
* under active development

OTOH, the Python DB API provides a specification of how database
modules should interface to the Python program. Since Python binds
based on name, that comes very close to the DBI kind of approach
as well.

In any case, most work usually goes into porting the SQL
layer of the application, not the interface layer beneath
it. Porting from Postgres to Oracle is not as hard at
the interface level, but you'll find that porting the
SQL concepts can be very time consuming.

Marc-Andre Lemburg

Professional Python Services directly from the Source  (#1, May 25 2004)
 >>> Python/Zope Consulting and Support ...        http://www.egenix.com/
 >>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
EuroPython 2004, Göteborg, Sweden                           12 days left

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::

More information about the DB-SIG mailing list