tags:

views:

11141

answers:

9

I'm evaluating and looking at using CherryPy for a project that's basically a javascript front-end from the client-side (browser) that talks to a Python web service on the back-end. So, I really need something fast and lightweight on the back-end that I can implement using Python that then speaks to the PostgreSQL db via an ORM (JSON to the browser).

I'm also looking at Django, which I like, since its ORM is built-in. However, I think Django might be a little more than I really need (i.e. more features than I really need == slower?).

Anyone have any experience with different Python ORM solutions that can compare and contrast their features and functionality, speed, efficiency, etc.?

+2  A: 

I think you might look at:

Autumn

Storm

Lukas Šalkauskas
Autumn is probably easier than Storm, but Storm includes many features that Autumn doesn't. Both of these options have limited documentation, although Storm is fixing that fast!
alecwh
Thank you, Autumn looks very nice and attractive, but has zero documentation, which is a deal breaker for me.
temoto
I just tried some of the examples on the Autumn page, and they don't even work with the version of the code my package manager installed. The posts in the google group are also old. Looks like the project is dying a slow death. Would not recommend using it.
Jason Miesionczek
Storm on the other hand, is quickly becoming my ORM of choice. Docs are getting better, and the API is clean and simple, though i am a bit more used to the ActiveRecord pattern employed by the Django ORM, i finding Storm to be easy to navigate.
Jason Miesionczek
Autum doesn't seem to have any activity for a year. http://groups.google.com/group/autumn-orm
Sridhar Ratnakumar
+1  A: 

I'd check out SQLAlchemy

It's really easy to use and the models you wrok with aren't bad at all.

Django uses sqlalchemy for it's ORM but using it by itself lets you use it's full power

here's a small example on creating and selecting orm objects

>>> ed_user = User('ed', 'Ed Jones', 'edspassword')
>>> session.add(ed_user)
>>> our_user = session.query(User).filter_by(name='ed').first() 
>>> our_user
    <User('ed','Ed Jones', 'edspassword')>
Yon
Django does _not_ use sqlalchemy for it's ORM. There has been some work done to make sqlalchemy an optional ORM, but it's not complete.
sherbang
+16  A: 

@Yon

Django uses sqlalchemy for it's ORM but using it by itself lets you use its full power

Django does not use SQLAlchemy, Django has its own ORM.

SQLAlchemy is more full-featured and powerful (uses the DataMapper pattern). Django ORM has a cleaner syntax and is easier to write for (ActiveRecord pattern). I don't know about performance differences.

I wouldn't worry about Django being "too heavy," though. It's decoupled enough that you can use the pieces you need without having to import the rest.

Carl Meyer
But if you don't like Django's ORM, and want to use SA, for example, you lose a lot of django's features, like admin. Not a deal breaker, but a skinned knee.
Gregg Lind
True, but irrelevant to the question, which was simply about choosing a Python ORM; not about automatically-generated admin interfaces or other framework components.
Carl Meyer
+12  A: 

I usually use SQLAlchemy. It's pretty powerful and is probably the most mature python ORM.

If you're planning on using CherryPy, you might also look into dejavu as it's by Robert Brewer (the guy that is the current CherryPy project leader). I personally haven't used it, but I do know some people that love it.

SQLObject is a little bit easier to use ORM than SQLAlchemy, but it's not quite as powerful.

Personally, I wouldn't use the Django ORM unless I was planning on writing the entire project in Django, but that's just me.

Jason Baker
SQLObject is great - simple-to-use, database-independent and it can actually make the tables for you! (I'm lazy).
Lucas Jones
+5  A: 

We use Elixir alongside SQLAlchemy and have liked it so far. Elixir puts a layer on top of SQLAlchemy that makes it look more like the "ActiveRecord pattern" counter parts.

toby
SQLAlchemy supports OOP and functional styles out of the box, Elixir adds declarative programming style (mostly for model declarations but can be exdended) on top of it.
muhuk
+1  A: 

There is no conceivable way that the unused features in Django will give a performance penalty. Might just come in handy if you ever decide to upscale the project.

there is a *concievable* way
bukzor
+9  A: 

Storm has arguably the simplest API:

  class Foo:
      __storm_table__ 'foos'
      id = Int(primary=True)


  class Thing:
      __storm_table__ 'things'
      id = Int(primary=True)
      name = Unicode()
      description = Unicode()
      foo_id = Int()
      foo = Reference(foo_id, Foo.id)

  db = create_database('sqlite:')
  store = Store(db)

  foo = Foo()
  store.add(foo)
  thing = Thing()
  thing.foo = foo
  store.add(thing)
  store.commit()

And it makes it painless to drop down into raw SQL when you need to:

store.execute('UPDATE bars SET bar_name=? WHERE bar_id like ?', []) 
store.commit()
Thanks for showing a complete example. Storm really is easy.
alecwh
It should be noted that Storm only supports MySQL and PostgreSQL at the current moment. Oracle support is in the works though.
Jason Baker
It also supports SQLite as the above example suggests
southof40
+5  A: 

SQLAlchemy's declarative extension, which is becoming standard in 0.5, provides an all in one interface very much like that of Django or Storm. It also integrates seamlessly with classes/tables configured using the datamapper style:

Base = declarative_base()

class Foo(Base):
      __tablename__ 'foos'
      id = Column(Integer, primary_key=True)

class Thing(Base):
    __tablename__ = 'things'

    id = Column(Integer, primary_key=True)
    name = Column(Unicode)
    description = Column(Unicode)
    foo_id = Column(Integer, ForeignKey('foos.id'))
    foo = relation(Foo)

engine = create_engine('sqlite://')

Base.metadata.create_all(engine)  # issues DDL to create tables

session = sessionmaker(bind=engine)()

foo = Foo()
session.add(foo)
thing = Thing(name='thing1', description='some thing')
thing.foo = foo  # also adds Thing to session
session.commit()
zzzeek
+1  A: 

SQLAlchemy is very, very powerful. However it is not thread safe make sure you keep that in mind when working with cherrypy in thread-pool mode.

Anon