peewee 3.18.2


pip install peewee

  Latest version

Released: Jul 08, 2025

Project Links

Meta
Author: Charles Leifer

Classifiers

Development Status
  • 5 - Production/Stable

Intended Audience
  • Developers

License
  • OSI Approved :: MIT License

Operating System
  • OS Independent

Programming Language
  • Python
  • Python :: 2
  • Python :: 2.7
  • Python :: 3
  • Python :: 3.4
  • Python :: 3.5
  • Python :: 3.6
  • Python :: 3.7
  • Python :: 3.8
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13

Topic
  • Database
  • Software Development :: Libraries :: Python Modules
https://media.charlesleifer.com/blog/photos/peewee3-logo.png

peewee

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+

  • supports sqlite, mysql, mariadb, postgresql

  • tons of extensions

New to peewee? These may help:

Examples

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(default=datetime.datetime.now)
    is_published = BooleanField(default=True)

Connect to the database and create tables:

db.connect()
db.create_tables([User, Tweet])

Create a few rows:

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

# 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 = User.select().where(User.username.in_(usernames))
tweets = Tweet.select().where(Tweet.user.in_(users))

# We could accomplish the same using a JOIN:
tweets = (Tweet
          .select()
          .join(User)
          .where(User.username.in_(usernames)))

# How many tweets were published today?
tweets_today = (Tweet
                .select()
                .where(
                    (Tweet.created_date >= datetime.date.today()) &
                    (Tweet.is_published == True))
                .count())

# Paginate the user table and show me page 3 (users 41-60).
User.select().order_by(User.username).paginate(3, 20)

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

# Do an atomic update (for illustrative purposes only, imagine a simple
# table for tracking a "count" associated with each URL). We don't want to
# naively get the save in two separate steps since this is prone to race
# conditions.
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 irc.libera.chat, or post to the mailing list, http://groups.google.com/group/peewee-orm . If you would like to report a bug, create a new issue on GitHub.

Still want more info?

https://media.charlesleifer.com/blog/photos/wat.jpg

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:

3.18.2 Jul 08, 2025
3.18.1 Apr 30, 2025
3.18.0 Apr 29, 2025
3.17.9 Feb 05, 2025
3.17.8 Nov 12, 2024
3.17.7 Oct 15, 2024
3.17.6 Jul 06, 2024
3.17.5 May 10, 2024
3.17.4 May 10, 2024
3.17.3 Apr 17, 2024
3.17.2 Apr 16, 2024
3.17.1 Feb 05, 2024
3.17.0 Oct 13, 2023
3.16.3 Aug 14, 2023
3.16.2 Apr 21, 2023
3.16.1 Apr 18, 2023
3.16.0 Feb 27, 2023
3.15.4 Nov 11, 2022
3.15.3 Sep 22, 2022
3.15.2 Aug 26, 2022
3.15.1 Jul 12, 2022
3.15.0 Jun 17, 2022
3.14.10 Mar 07, 2022
3.14.9 Feb 15, 2022
3.14.8 Oct 28, 2021
3.14.7 Oct 27, 2021
3.14.6 Oct 27, 2021
3.14.4 Mar 19, 2021
3.14.3 Mar 11, 2021
3.14.2 Mar 04, 2021
3.14.1 Feb 07, 2021
3.14.0 Nov 07, 2020
3.13.3 Apr 24, 2020
3.13.2 Mar 27, 2020
3.13.1 Dec 06, 2019
3.13.0 Dec 06, 2019
3.12.0 Nov 25, 2019
3.11.2 Sep 24, 2019
3.11.1 Sep 23, 2019
3.11.0 Sep 19, 2019
3.10.0 Aug 03, 2019
3.9.6 Jun 06, 2019
3.9.5 Apr 26, 2019
3.9.4 Apr 14, 2019
3.9.3 Mar 23, 2019
3.9.2 Mar 06, 2019
3.9.1 Mar 06, 2019
3.9.0 Mar 06, 2019
3.8.2 Jan 17, 2019
3.8.1 Jan 07, 2019
3.8.0 Dec 16, 2018
3.7.1 Oct 05, 2018
3.7.0 Sep 06, 2018
3.6.4 Jul 18, 2018
3.6.3 Jul 18, 2018
3.6.2 Jul 18, 2018
3.6.1 Jul 17, 2018
3.6.0 Jul 17, 2018
3.5.2 Jul 03, 2018
3.5.1 Jun 27, 2018
3.5.0 May 29, 2018
3.4.0 May 20, 2018
3.3.4 May 04, 2018
3.3.3 May 03, 2018
3.3.2 May 01, 2018
3.3.1 Apr 26, 2018
3.3.0 Apr 24, 2018
3.2.5 Apr 19, 2018
3.2.4 Apr 18, 2018
3.2.3 Apr 16, 2018
3.2.2 Apr 01, 2018
3.2.1 Mar 31, 2018
3.2.0 Mar 28, 2018
3.1.7 Mar 27, 2018
3.1.6 Mar 26, 2018
3.1.5 Mar 14, 2018
3.1.4 Mar 14, 2018
3.1.3 Mar 10, 2018
3.1.2 Feb 28, 2018
3.1.1 Feb 27, 2018
3.1.0 Feb 23, 2018
3.0.19 Feb 21, 2018
3.0.18 Feb 14, 2018
3.0.17 Feb 10, 2018
3.0.16 Feb 08, 2018
3.0.15 Feb 08, 2018
3.0.14 Feb 07, 2018
3.0.13 Feb 06, 2018
3.0.12 Feb 05, 2018
3.0.11 Feb 04, 2018
3.0.10 Feb 02, 2018
3.0.9 Feb 01, 2018
3.0.8 Jan 31, 2018
3.0.7 Jan 31, 2018
3.0.6 Jan 30, 2018
3.0.5 Jan 30, 2018
3.0.4 Jan 30, 2018
3.0.3 Jan 30, 2018
3.0.2 Jan 29, 2018
3.0.1 Jan 29, 2018
2.10.2 Oct 08, 2017
2.10.1 May 09, 2017
2.10.0 May 08, 2017
2.9.2 Apr 07, 2017
2.9.1 Mar 12, 2017
2.9.0 Mar 06, 2017
2.8.8 Feb 26, 2017
2.8.7 Feb 22, 2017
2.8.5 Oct 03, 2016
2.8.4 Oct 02, 2016
2.8.3 Aug 25, 2016
2.8.2 Aug 09, 2016
2.8.1 May 04, 2016
2.8.0 Jan 14, 2016
2.7.4 Dec 04, 2015
2.7.3 Nov 21, 2015
2.7.2 Nov 21, 2015
2.7.1 Nov 20, 2015
2.7.0 Nov 20, 2015
2.6.4 Sep 22, 2015
2.6.3 Jul 07, 2015
2.6.2 Jul 02, 2015
2.6.1 May 29, 2015
2.6.0 Apr 22, 2015
2.5.1 Apr 05, 2015
2.5.0 Mar 21, 2015
2.4.7 Feb 04, 2015
2.4.6 Jan 22, 2015
2.4.5 Dec 22, 2014
2.4.4 Dec 03, 2014
2.4.3 Nov 24, 2014
2.4.2 Nov 08, 2014
2.4.1 Oct 28, 2014
2.4.0 Oct 18, 2014
2.3.3 Sep 30, 2014
2.3.2 Sep 15, 2014
2.3.1 Aug 19, 2014
2.3.0 Aug 12, 2014
2.2.5 Jul 08, 2014
2.2.4 May 14, 2014
2.2.3 Apr 21, 2014
2.2.2 Mar 13, 2014
2.2.1 Feb 12, 2014
2.2.0 Jan 29, 2014
2.1.7 Dec 26, 2013
2.1.6 Nov 19, 2013
2.1.5 Oct 22, 2013
2.1.4 Aug 07, 2013
2.1.3 Jun 29, 2013
2.1.2 May 22, 2013
2.1.1 Apr 14, 2013
2.1.0 Apr 02, 2013
2.0.9 Mar 25, 2013
2.0.8 Mar 03, 2013
2.0.7 Jan 26, 2013
2.0.6 Jan 09, 2013
2.0.5 Dec 21, 2012
2.0.4 Nov 18, 2012
2.0.3 Oct 30, 2012
2.0.2 Oct 15, 2012
2.0.1 Oct 09, 2012
2.0.0 Oct 08, 2012
1.0.0 Aug 26, 2012
0.9.9 Jul 03, 2012
0.9.8 Jun 23, 2012
0.9.7 Jun 04, 2012
0.9.6 May 09, 2012
0.9.5 Apr 24, 2012
0.9.4 Apr 09, 2012
0.9.3 Apr 06, 2012
0.9.2 Mar 20, 2012
0.9.1 Mar 13, 2012
0.9.0 Feb 01, 2012
0.8.2 Jan 31, 2012
0.8.1 Jan 29, 2012
0.8.0 Jan 08, 2012
0.7.5 Dec 28, 2011
0.7.4 Nov 17, 2011
0.7.3 Oct 01, 2011
0.7.2 Sep 29, 2011
0.7.1 Sep 17, 2011
0.7.0 Sep 14, 2011
0.6.2 Sep 07, 2011
0.6.1 Jul 18, 2011
0.6.0 Jul 18, 2011
0.5.0 Jun 30, 2011
0.4.0 Jun 08, 2011
0.3.2 Feb 12, 2011
0.3.1 Jan 31, 2011
0.3.0 Nov 28, 2010
0.2.2 Nov 25, 2010
0.2.1 Nov 23, 2010
0.2.0 Nov 23, 2010
0.1.1 Nov 19, 2010
0.1.0 Oct 18, 2010
No dependencies