<p>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).</p>

<p>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?).</p>

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

[{'answer_id': 53440, 'author': 'Lukas Šalkauskas', 'author_id': 5369, 'author_profile': 'https://Stackoverflow.com/users/5369', 'pm_score': 1, 'selected': False, 'text': '<p>I think you might look at:</p>\n\n<p><a href="http://autumn-orm.org/" rel="nofollow noreferrer">Autumn</a></p>\n\n<p><a href="https://storm.canonical.com/" rel="nofollow noreferrer">Storm</a></p>\n'}, {'answer_id': 53463, 'author': 'Yon', 'author_id': 3117, 'author_profile': 'https://Stackoverflow.com/users/3117', 'pm_score': -1, 'selected': False, 'text': '<p>I\'d check out <a href="http://www.sqlalchemy.org/" rel="nofollow noreferrer">SQLAlchemy</a> </p>\n\n<p>It\'s really easy to use and the models you work with aren\'t bad at all. <strike>Django uses SQLAlchemy for it\'s ORM</strike> but using it by itself lets you use it\'s full power.</p>\n\n<p>Here\'s a small example on creating and selecting orm objects</p>\n\n<pre><code>&gt;&gt;&gt; ed_user = User(\'ed\', \'Ed Jones\', \'edspassword\')\n&gt;&gt;&gt; session.add(ed_user)\n&gt;&gt;&gt; our_user = session.query(User).filter_by(name=\'ed\').first() \n&gt;&gt;&gt; our_user\n    &lt;User(\'ed\',\'Ed Jones\', \'edspassword\')&gt;\n</code></pre>\n'}, {'answer_id': 54046, 'author': 'Carl Meyer', 'author_id': 3207, 'author_profile': 'https://Stackoverflow.com/users/3207', 'pm_score': 8, 'selected': True, 'text': '<p>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.</p>\n\n<p>SQLAlchemy also has a <a href="http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/declarative/index.html" rel="noreferrer">declarative layer</a> that hides some complexity and gives it a ActiveRecord-style syntax more similar to the Django ORM.</p>\n\n<p>I wouldn\'t worry about Django being "too heavy."  It\'s decoupled enough that you can use the ORM if you want <a href="https://stackoverflow.com/a/2180431/623735">without having to import the rest</a>.</p>\n\n<p>That said, if I were already using CherryPy for the web layer and just needed an ORM, I\'d probably opt for SQLAlchemy.</p>\n'}, {'answer_id': 54300, 'author': 'Jason Baker', 'author_id': 2147, 'author_profile': 'https://Stackoverflow.com/users/2147', 'pm_score': 5, 'selected': False, 'text': '<p>I usually use <a href="http://www.sqlalchemy.org/" rel="noreferrer">SQLAlchemy</a>.  It\'s pretty powerful and is probably the most mature python ORM.</p>\n\n<p>If you\'re planning on using CherryPy, you might also look into <a href="http://www.aminus.net/dejavu" rel="noreferrer">dejavu</a> 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.</p>\n\n<p><a href="http://www.sqlobject.org" rel="noreferrer">SQLObject</a> is a little bit easier to use ORM than SQLAlchemy, but it\'s not quite as powerful.</p>\n\n<p>Personally, I wouldn\'t use the Django ORM unless I was planning on writing the entire project in Django, but that\'s just me.</p>\n'}, {'answer_id': 55779, 'author': 'airportyh', 'author_id': 5304, 'author_profile': 'https://Stackoverflow.com/users/5304', 'pm_score': 3, 'selected': False, 'text': '<p>We use <a href="http://elixir.ematia.de/trac/wiki" rel="noreferrer">Elixir</a> 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.</p>\n'}, {'answer_id': 186179, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>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.</p>\n'}, {'answer_id': 384781, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 6, 'selected': False, 'text': '<p><a href="https://storm.canonical.com/" rel="nofollow noreferrer">Storm</a> has arguably the simplest API:</p>\n\n<pre><code>from storm.locals import *\n\nclass Foo:\n    __storm_table__ = \'foos\'\n    id = Int(primary=True)\n\n\nclass Thing:\n    __storm_table__ = \'things\'\n    id = Int(primary=True)\n    name = Unicode()\n    description = Unicode()\n    foo_id = Int()\n    foo = Reference(foo_id, Foo.id)\n\ndb = create_database(\'sqlite:\')\nstore = Store(db)\n\nfoo = Foo()\nstore.add(foo)\nthing = Thing()\nthing.foo = foo\nstore.add(thing)\nstore.commit()\n</code></pre>\n\n<p>And it makes it painless to drop down into raw SQL when you need to:</p>\n\n<pre><code>store.execute(\'UPDATE bars SET bar_name=? WHERE bar_id like ?\', []) \nstore.commit()\n</code></pre>\n'}, {'answer_id': 407556, 'author': 'zzzeek', 'author_id': 34549, 'author_profile': 'https://Stackoverflow.com/users/34549', 'pm_score': 4, 'selected': False, 'text': '<p>SQLAlchemy\'s <a href="http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/declarative.html" rel="nofollow noreferrer">declarative</a> 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:</p>\n\n<pre><code>Base = declarative_base()\n\nclass Foo(Base):\n    __tablename__ = \'foos\'\n    id = Column(Integer, primary_key=True)\n\nclass Thing(Base):\n    __tablename__ = \'things\'\n\n    id = Column(Integer, primary_key=True)\n    name = Column(Unicode)\n    description = Column(Unicode)\n    foo_id = Column(Integer, ForeignKey(\'foos.id\'))\n    foo = relation(Foo)\n\nengine = create_engine(\'sqlite://\')\n\nBase.metadata.create_all(engine)  # issues DDL to create tables\n\nsession = sessionmaker(bind=engine)()\n\nfoo = Foo()\nsession.add(foo)\nthing = Thing(name=\'thing1\', description=\'some thing\')\nthing.foo = foo  # also adds Thing to session\nsession.commit()\n</code></pre>\n'}, {'answer_id': 2510845, 'author': 'Anon', 'author_id': 301162, 'author_profile': 'https://Stackoverflow.com/users/301162', 'pm_score': -1, 'selected': False, 'text': '<p>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. </p>\n'}, {'answer_id': 4908742, 'author': 'Phil Loden', 'author_id': 509997, 'author_profile': 'https://Stackoverflow.com/users/509997', 'pm_score': 0, 'selected': False, 'text': '<p>I used Storm + SQLite for a small project, and was pretty happy with it until I added multiprocessing. Trying to use the database from multiple processes resulted in a "Database is locked" exception. I switched to SQLAlchemy, and the same code worked with no problems.</p>\n'}, {'answer_id': 5384974, 'author': 'entropo', 'author_id': 27963, 'author_profile': 'https://Stackoverflow.com/users/27963', 'pm_score': 3, 'selected': False, 'text': '<p>This seems to be the canonical reference point for high-level database interaction in Python:\n<a href="http://wiki.python.org/moin/HigherLevelDatabaseProgramming" rel="noreferrer">http://wiki.python.org/moin/HigherLevelDatabaseProgramming</a></p>\n\n<p>From there, it looks like <a href="http://www.aminus.net/dejavu" rel="noreferrer">Dejavu</a> implements Martin Fowler\'s DataMapper pattern fairly abstractly in Python.</p>\n'}, {'answer_id': 7439694, 'author': 'coleifer', 'author_id': 254346, 'author_profile': 'https://Stackoverflow.com/users/254346', 'pm_score': 7, 'selected': False, 'text': '<p>If you\'re looking for lightweight and are already familiar with django-style declarative models, check out peewee: \n<a href="https://github.com/coleifer/peewee">https://github.com/coleifer/peewee</a></p>\n\n<p>Example:</p>\n\n<pre><code>import datetime\nfrom peewee import *\n\nclass Blog(Model):\n    name = CharField()\n\nclass Entry(Model):\n    blog = ForeignKeyField(Blog)\n    title = CharField()\n    body = TextField()\n    pub_date = DateTimeField(default=datetime.datetime.now)\n\n# query it like django\nEntry.filter(blog__name=\'Some great blog\')\n\n# or programmatically for finer-grained control\nEntry.select().join(Blog).where(Blog.name == \'Some awesome blog\')\n</code></pre>\n\n<p>Check the <a href="http://peewee.readthedocs.org/en/latest/">docs</a> for more examples.</p>\n'}]
['https://Stackoverflow.com/questions/53428', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5499/']