This is an old copy of the Python FAQ. The information here may be outdated.

Are there any interfaces to database packages in Python?

Python has a standard DB-API interface (see PEP 249), and compatible implementations are available for all widely used database engines. See the Database Topic Guide for details.

Python 2.5 and later includes a DB-API compliant database package, sqlite3, which uses an embedded SQL database, SQLite.

>>> import sqlite3 as dbapi
>>> db = dbapi.connect("database.db")
>>> c = db.cursor()
>>> for record in c.execute("select * from table"):
...     print record

For earlier versions, this database can be downloaded separately (see

There’s also a standard bsddb package which provides an interface to the BerkeleyDB library. Interfaces to disk-based hashes such as dbm and gdbm are also included with standard Python.

For bridging Python and databases more naturally, there are a variety of object-relational mapping tools, like SQLObject and SQLAlchemy.

IronPython can use all DotNet database connections, of course, and Jython can use all Java database connections.

CATEGORY: library

CATEGORY: database


A Django site. rendered by a django application. hosted by webfaction.