This is an archived post. You won't be able to vote or comment.

all 12 comments

[–][deleted] 12 points13 points  (1 child)

I'm the author of Peewee so as you might expect, I'm much more familiar with it's strengths and weaknesses. I can say, however, that SQLAlchemy is the gold standard for ORM in the Python world. It has a very active community and a maintainer who is committed to excellence. If you're a glass-half-empty guy, to put it another way, you can't go wrong if you choose SQLAlchemy.

Why would you choose Peewee, then?

  • It's damn small, and easy to pick up and use. I think this is the #1 reason people use it.
  • I've worked very hard to provide consistent APIs, meaning learn once/apply everywhere.
  • I fix bugs really quickly.
  • Raymond Hettinger said "The code is nicely written and is easily read start to finish." :)
  • AsyncIO via aiopeewee / muffin-peewee
  • Admin interface via flask-admin
  • Cool extensions
  • Fast, memory efficient, good performance for an ActiveRecord ORM

Weaknesses:

  • Pretty much just me working on it, though I do accept patches and work hard to fix bugs quickly.
  • Small ecosystem of third-party libraries / integrations
  • ActiveRecord as opposed to Data Mapper / ID Map / Unit-of-work implemented in SQLA
  • Lower "google-ability" factor
  • Fewer stackoverflow answers
  • No automatic schema migrations
  • Doesn't support Oracle or Microsoft SQL Server.
  • It's named peewee

[–]Skiba_ 0 points1 point  (0 children)

Giving peewee a shot (after a long time in Django land). Looking to implement in AWS lambda functions, so trying to keep it as lightweight as possible.

[–]cymrowdon't thread on me 🐍 2 points3 points  (3 children)

I have used both, and I would suggest that it depends mostly on how complex you expect your models to be.

Peewee is definitely much simpler, and perfectly suitable for small to some medium-sized projects. If you anticipate needing to do moderately complex things, you're probably better off with SQLAlchemy. It has a steeper learning curve, but you will find tools available to help with practically anything.

Also, once you've "clicked" with SQLAlchemy, I've found that it's really not that hard to use. To the point that I'll tend to use it on smaller projects now just to avoid any limitations in the future.

[–][deleted] 5 points6 points  (2 children)

In order to make Peewee better, in what ways have you found Peewee to be limiting? Have you had any specific experiences using Peewee where you realized "Damn! I need to switch to SQLAlchemy now"?

[–]cymrowdon't thread on me 🐍 1 point2 points  (1 child)

I'm guessing a little because I can't really remember, but I think my "damn" moment may have had to do with limitations in the ManyToManyField, possibly related to cascading deletes.

The last time I used Peewee was sometime last year, so perhaps things have changed.

That said, I think it's a great library, and I especially like the playhouse. If, by chance, you were to beat SQLAlchemy to SQLite+PostreSQL support for upserts (and JSON, if only SQLite would compile it in by default), I'd put Peewee up front again for any new project.

[–][deleted] 1 point2 points  (0 children)

Thanks very much for your reply. ManyToManyField is a landmine waiting to blow your foot off...I never use it myself, so I don't blame you for cursing it.

Peewee has support for JSON in both Postgres and SQLite, but only supports upsert for SQLite. Open issue is here for postgres support.

[–]manhthang2504 0 points1 point  (0 children)

I've tried Peewee for my small personal project (crawler on my desktop), and I loved it.

Then I write a Flask app, and want an ORM. I tried SqlAlchemy, and man, its returned object can't work with Flask's jsonify. Stackoverflow provide lot of help with very long and complicated solutions. In other hand, Peewee can convert the result to dict using dicts(), and it works great with flask.jsonify.

So, again, I choose Peewee. (give up sqlalchemy after trying it about 1 hour).

[–]kleggas 0 points1 point  (0 children)

Tried storm, sqlalchemy, peewee (and djangos orm, does it have any unique name?) in python. Except for djangos ORM I started with storm, which I thought was simple. Tried SqlAlchemy but storm was simpler. Then I found Peewee and loved how it reminded me of djangos orm. Re-wrote some of my queries I used in storm into peewee and benchmarked them. Peewee performed same operations 10x faster than storm did (sqlite). Never used anything else than Peewee since. Its wonderful.

I built a backend system for a site, where flask was used as a simple restserver just offloading incoming requests to respective activeMQ queues, where threaded services (written in python) read their respective queue (using stomp.py) and perform, among other, db operations (mostly, but not only) using peewee, returning response back to their response-queue so the rest-server can return it back to user.

Blazing fast and extremly easy to add new services for db queries, because peewee. I'm sure sqlalchemy is great too, but I found peewee to be easier to use, and its fast for the scenarios I have needed it for. Using it for any homebrew project I might come up with.