Many people ask if they can use the web2py Database Abstraction Layer without using the framework.
Yes, this is possible, assuming you have the proper database drivers (psycopg2 for PostgreSQL, mysqldb for MySQL, cs_oracle for Oracle, pyodbc for MSSQL, DB2, FireBird)
Example:
from gluon.sql import DAL, Field
db=DAL('postgres://username:password@localhost/database')
db.define_table('friend',Field('name'))
print db.tables
db.field.insert(name='Tim')
print db.friend.fields
for row in db().select(db.friend.name,orderby=db.friend.name):
print row.name
You can also use it in the google app engine
db=DAL('gae')