A very thin wrapper around Python's DB API 2.0 standard.
Alpha
Just a couple of little wrappers & helper methods for manipulating databases with Python.
- Python 2.6+
- A DB API 2.0 compatible database driver
pip install dbutil
import dbutil
conn = dbutil.connect("mysql://root@localhost/foo_db")
# ... do stuff ...
conn.close()
import dbutil
with dbutil.connect(...) as conn:
# ... do stuff ...
num_users = conn.one("SELECT COUNT(*) FROM users")
print num_users
user = conn.row("SELECT * FROM users WHERE id=%s", (1,))
print user
users = conn.all("SELECT * FROM users")
print users
for user in conn.iter("SELECT * FROM users"):
print user
def print_user(user):
print user
conn.each(print_user, "SELECT * FROM users")
emails = conn.map(lambda row: row["email"], "SELECT * FROM users")
conn.execute("INSERT INTO users VALUES (%s, %s, SHA(%s))", (1, 'me@foo.com', 'password'))
# standard DB API stuff works too
crs = conn.cursor()
# ...
This software is licensed under the terms of the MIT License.
Please log defects and feature requests using the issue tracker on github.
python-dbutil was written by Tom Lee.