views:

127

answers:

3

I'm looking for an ORM that allows me to do bulk inserts, as well as create code based on python classes. I tried sqlobject, it worked fine for creating the tables but inserting was unacceptibly slow for the amount of data I wanted to insert. If such an ORM doesn't exist any pointers on classes that can help with things like sanitizing input and building SQL strings would be appreciated.

+4  A: 

You might want to try SQLAlchemy.

Mike Hordecki
We use SQLAlchemy and it works just fine for table creation and bulk inserts. Depending on the database (and the DBAPI), SQLQAlchemy has an executemany() for bulk inserts, see http://www.sqlalchemy.org/docs/05/sqlexpression.html#executing-multiple-statements
stephan
A: 

I believe sqlalchemy has bulk inserts, but I haven't ever used it. However, it stacks up favorably in benchmark tests according to this this reviewer.

EDIT: It doesn't seem clear how he's using SQLAlchemy...whether it's the actual ORM or just query code. Reading the blog entry, I assumed the point was to play with the ORM, but a few commentors seem to assume that he's using query-code and that if it were the ORM it would be much slower.

David Berger
A: 

I'm not familiar with sqlobject, but for bulk inserts typically you want to make sure this is done in a transaction, so your not commiting for each manipulation.

In sqlobject it looks like you can do this by using the transactions object to control commits. You probably need to turn of the default AutoCommit flag as well for this to function properly.

http://www.sqlobject.org/SQLObject.html#id45

monkut