Python Portable SQL Database API

Python’s portable database API provides script portability between different vendor-specific SQL database packages. For each vendor, install the vendor-specific extension module, but write your scripts according to the portable database API. Your database scripts will largely continue working unchanged after migrating to a different underlying vendor package.

Note that database extension modules are not part of the Python standard library (you must fetch and install them separately). See Section 1.20 earlier in this book for simpler alternatives. Hint: the Python-based gadly SQL database system allows scripts to be prototyped with the database API, before you install a vendor package.

API Usage Example

from dcoracle import Connect
connobj = connect("user/password@system")
cursobj = connobj.cursor(  )

value1, value2 = 'developer', 39
query = 'SELECT name, shoesize FROM empl WHERE job = ? AND 
    age = ?'  
cursobj.execute(query, (value1, value2))

results = cursobj.fetchall(  )
for (name, size) in results:
    print name, size

Module Interface

This and the following sections provide a partial list of exports; see the full API specification at for details omitted here.


Constructor for connection objects; represents a connection to the database. Parameters are vendor-specific.


String giving type of parameter marker formatting (e.g., “qmark” = “?” style).


Exception raised for important warnings such as data ...

Get Python Pocket Reference, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.