July 24, 2011 10:07 / 2 comments / peewee postgresql python

Over the past month I've been working on adding support for both MySQL and PostgreSQL to peewee. I'm happy to say that after a couple weekend hack sessions all tests are now passing.

I've updated the documentation to include a little blurb on how you might use peewee with PostgreSQL:

psql_db = peewee.PostgresqlDatabase('my_database', user='postgres')

class PostgresqlModel(peewee.Model):
    """A base model that will use our MySQL database"""
    class Meta:
        database = psql_db

class Blog(PostgresqlModel):
    author = peewee.CharField()
    # etc, etc

# when you're ready to start querying, remember to connect
psql_db.connect()

If you're interested in getting the gist of how peewee works, check out the "common uses" documentation. There's also an example app which is running here.

Heads up

Peewee can do a lot, but it is not a replacement for SQL - it also does not try to offer the power or expressiveness of some other ORMs, notably SQLAlchemy. That being said, if you want something:

  • lightweight
  • easy to understand
  • hackable

then this might be the project you're looking for.

Comments (2)

  • Daniel | July 2011, at 18:04

    Reading your code was really inspiring when I was working on https://github.com/dmr/Ldtools and other projects. Although this might sound like the spam comments I get all the time, keep up the good work! Are there any projects using peewee you know about?


  • Charles | July 2011, at 20:25

    Thanks for the encouragement, Daniel, and I'm glad you found the project helpful! While I have not seen any wild peewee examples, I have used it myself on a number of projects...being familiar with django I find it really easy to use peewee and "get what I want" using flask. I've also used it for some non-web-app stuff as well with good results.


Commenting has been closed, but please feel free to contact me