dulce – a little Python ORM

Not sure how I got started with this, I think I was looking at some ORM-style APIs and wanted to try my hand at it. Not too surprising, my result is reminiscent of pyparsing – using operator ‘+’ to define table joins, and __call__ to execute joins and queries. I called this little project “dulce”, as it is really little more than a syntactic sweet, a wrapper around a Python list of Python objects. But here’s two things I like:

  • a simple join syntax:
    wishlists = customers.join_on("id") + wishitems.join_on("custid") + catalog.join_on("sku")
  • a simple query-by-key syntax:
    print customers.id["0030"].name

Also, all queries and joins return a new full-fledged dulce Table object, so chaining queries, or exporting the output of joins is very easy.  And there is no schema definition, the schema “emerges” based on the object attributes used in queries and joins.

As it is pure Python, I think it would be ridiculous to make claims about how fast this is, although with psyco acceleration, loading and joining a table with 10,000+ zip codes takes about 2 seconds. I guess the biggest advantages would be:

  • pure Python portability
  • small Python footprint – single script file, about 500 lines long, including docs
  • quick start to organize a collection of objects
  • simple join interface

I created a SourceForge project for this little thing, you can find it here. I haven’t even packaged any releases yet, but the source can be extracted from the project SVN repository.

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: