sqlobject vs mysqldb module

Jeffrey E. Forcier jforcier at strozllc.com
Tue Aug 9 19:48:09 CEST 2005

Skip is correct, they're somewhat different:

SQLObject is an 'ORM' or 'Object-Relational Mapping', meaning that it
allows you to handle everything related to the database with objects.
The table handles are objects, the result set is an object, the
individual rows in a result set are objects with attributes for the
fields/columns. So instead of "SELECT id,name FROM people WHERE
location='New York'", you'd do something like the following:

for row in People.selectBy(location='New York'):
    print "id: %s, name: %s" % (row.id,row.name)

This is nice if you value object-oriented code very highly, and don't
have any specific SQL-level tricks you wish to employ (although
SQLObject can handle those as well, I'm told, it's just not its main

MySQLDB, while I haven't used it specifically, is probably similar to
its Postgres cousins pyPgSQL and psycopg, in that it just provides a
Python DB API compliant interface to the database (see

Such modules do not provide much or any object orientation, sticking
with a more low-level approach of making SQL calls and getting
dictionaries back, to wit:

conn = [module_name].connect(connection_args)
cursor = conn.cursor()
cursor.execute("SELECT id,name FROM people WHERE location='New York'")
print cursor.fetchall()

Anyway, sorry if that's over your head (it's hard to tell your
experience level from your post), but the basic gist is that SQLObject
is good for a higher-level and very easy-to-use database connection,
and MySQLDB is probably good if you're very comfortable with SQL and
not so much with object-oriented programming (or if you have any other
reason to prefer straight SQL queries).

More information about the Python-list mailing list