dbx is a simple SQL database abstraction layer for Python.
The goal of dbx is to make using a SQL database as simple as possible while providing a consistent API across different databases.
The Python DB-API is powerful, yet complex. An application that simply needs to execute a query and iterate over the results does not need all that power and can greatly benefit from a simpler interface.
This software is public domain.
Download the pydbx package. The latest published pydbx package is pydbx-0.14.tar.gz.
Unpack the pydbx package:
tar -xf pydbx-0.14.tar
As root, install the dbx package:
python setup.py install
dbx supports the following databases:
This is an example using DB-API:
import MySQLdb conn = MySQLdb.connect(db="test", host="localhost", user="user", passwd="pass") cursor = conn.cursor(MySQLdb.cursors.DictCursor) cursor.execute("SELECT name, phone FROM User") rows = cursor.fetchall() for i in rows: print i["name"], i["phone"] cursor.close() conn.close()
This is an example using dbx:
import dbx.mysql as dbx db = dbx.MySQL("test", "localhost", "user", "pass") rows = db.listQuery("SELECT name, phone FROM User") for i in rows: print i["name"], i["phone"] db.close()
As you can see, it is easier to use dbx because you do not need to deal with cursors. You also do not need to worry about how results are returned, since they are always returned as dictionaries. Exceptions are also handled consistently.