[Tutor] when is object relational mapping for Python warranted?

Tim Golden mail at timgolden.me.uk
Wed Jun 11 10:36:26 CEST 2008


Che M wrote:
> I'm curious whether I should consider learning either SQLObject 
> or SQLAlchemy, and whether my needs would be worth it.  I am
> learning to use SQlite databases for fairly simple storage and later
> search, and have only recently learned about object relational
> mapping (ORM).  "Fairly simple" = 4-6 tables with no more than
> 2-10 fields each, 100-5,000 records, with queries doing basic LIKE 
> and other matches, nothing fancy.
> 
> I'd like to hear opinions on when it is worth it to use these ORM tools
> for a Python database application, that is, in terms of the complexity
> of the database or queries or the application, or when basic Python 
> and SQL is sufficient.  It's a personal preference, I'm sure, but I just 
> wanted to get some opinions.  Also, if there is an opinion about either 
> of these two ORMs in terms of learning curve, quality, etc.

Good question, I think.

My answer would be: pick an ORM to learn anyway. You can't go
far wrong knowing what's there and the learning curves are not steep.
You've mentioned sqlalchemy and SQLObject. There are also Storm,
MotherDb and Elixir (which is an easier layer over sqlalchemy).
SQLObject is more mature but sqlalchemy is quite popular and has
a lot of community support. The others are relatively new and I don't
know too much about them.

But the other side of the coin is: when do you need an ORM at all?
I'm a professional SQL programmer so I tend to find extra tools
getting in the way. If I'm dealing with relational data, I think in SQL
and, no matter how good the ORM's syntax, I find it a distraction.
But where I *do* find an ORM useful is in dealing with very simple 
interactions with one or two joins which are handled automatically
and which save me writing fairly tedious boilerplate. In short, I use
ORMs for small projects, but not for big ones. So far.

TJG



More information about the Tutor mailing list