Home > Articles > Open Source > Python

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

DB-API II

The most usual way of connecting to a database in Python is to use one of the databases supported by DB-API II modules. DB-API II is the current standard for low-level access to any relational database. If you don't use any extensions, and if you write database-independent SQL, your DB-API II–compatible code should work on any of the supported databases. Writing database-independent SQL code might well be impossible if you consider that, for instance, MySQL doesn't support subqueries or that the Oracle syntax for outer joins differs from the ANSI standard. And no database offers the same mechanism to access the automatically incremented primary key values after inserting a row. Some databases don't offer any mechanism for that at all.

Supported databases include DB/2, Informix, Interbase, Ingres, MySQL, Oracle, PostgreSQL, SAP, and Sybase. However, you need to check in advance whether the particular database that you want to use is supported on your particular operating system. For instance, psycopg, is reported to work only on Solaris, Linux, and OS/X—that is to say, it has been tested on UNIX.

If your database isn't supported directly but supports ODBC, you can always try to use one of the DB-API II–compliant ODBC modules. The most famous of these is mxODBC. And if you're using Jython, you can use JDBC—either directly, because Jython enables you to access all Java class libraries, or via a DB-API II–compliant wrapper, zxJDBC.

If you are securely wedded to the Microsoft world, you can also try the DB-API II bindings to ADO, an alternative to ODBC (see http://adodbapi.sourceforge.net/).

  • + Share This
  • 🔖 Save To Your Account