Skip to content
a small, expressive orm -- supports postgresql, mysql and sqlite
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Add set_time_zone() method to PostgresqlDatabase. Apr 16, 2019
examples Just another example for hexastore. Mar 7, 2019
playhouse Basic / minimal json field for MySQL. Apr 9, 2019
tests Verify behavior of insert/returning+objects. Apr 18, 2019
.gitignore Update gitignore. Jan 19, 2019
.travis.yml Attempt to build latest sqlite with CI Jul 19, 2018 changelog notes, remove 38 build from failure list. Apr 14, 2019
LICENSE Adding a license Oct 12, 2010 Include C sources in source dist. Jul 7, 2018
README.rst Links to interactive section in short-nav. Mar 6, 2019
TODO.rst Enhance the playhouse.kv to use upsert for all backend dbs. Mar 4, 2019 Fix transactional behavior in bench Sep 8, 2018 Refactor save() logic, use pk from INSERT...RETURNING if possible. Apr 18, 2019 Refactoring / cleaning-up test runner. May 1, 2018



Peewee is a simple and small ORM. It has few (but expressive) concepts, making it easy to learn and intuitive to use.

  • a small, expressive ORM
  • python 2.7+ and 3.4+ (developed with 3.6)
  • supports sqlite, mysql and postgresql
  • tons of extensions

New to peewee? These may help:


Defining models is similar to Django or SQLAlchemy:

from peewee import *
import datetime

db = SqliteDatabase('my_database.db')

class BaseModel(Model):
    class Meta:
        database = db

class User(BaseModel):
    username = CharField(unique=True)

class Tweet(BaseModel):
    user = ForeignKeyField(User, backref='tweets')
    message = TextField()
    created_date = DateTimeField(
    is_published = BooleanField(default=True)

Connect to the database and create tables:

db.create_tables([User, Tweet])

Create a few rows:

charlie = User.create(username='charlie')
huey = User(username='huey')

# No need to set `is_published` or `created_date` since they
# will just use the default values we specified.
Tweet.create(user=charlie, message='My first tweet')

Queries are expressive and composable:

# A simple query selecting a user.
User.get(User.username == 'charlie')

# Get tweets created by one of several users.
usernames = ['charlie', 'huey', 'mickey']
users =
tweets =

# We could accomplish the same using a JOIN:
tweets = (Tweet

# How many tweets were published today?
tweets_today = (Tweet
                    (Tweet.created_date >= &
                    (Tweet.is_published == True))

# Paginate the user table and show me page 3 (users 41-60)., 20)

# Order users by the number of tweets they've created:
tweet_ct = fn.Count(
users = (User
         .select(User, tweet_ct.alias('ct'))
         .join(Tweet, JOIN.LEFT_OUTER)

# Do an atomic update
Counter.update(count=Counter.count + 1).where(Counter.url == request.url)

Check out the example twitter app.

Learning more

Check the documentation for more examples.

Specific question? Come hang out in the #peewee channel on, or post to the mailing list, . If you would like to report a bug, create a new issue on GitHub.

Still want more info?

I've written a number of blog posts about building applications and web-services with peewee (and usually Flask). If you'd like to see some real-life applications that use peewee, the following resources may be useful:

You can’t perform that action at this time.