Skip to main content

Peewee ORM integration for Flask framework

Project description

The Flask-PW – Peewee ORM intergration for Flask framework.

The plugin configures DB connection and provides some tools such as migrations and signals. It also provides Peewee ORM support for Flask-Debugtoolbar


  • python 2.7+,3.4+


Flask-PW should be installed using pip:

pip install flask-pw



Flask-PW settings (default values):

# Connection URI
PEEWEE_DATABASE_URI = 'sqlite:///peewee.sqlite'

# Connection params (for example for pgsql: { encoding: 'utf-8' })

# Path to directory which contains migrations
PEEWEE_MIGRATE_DIR = 'migrations'

# Name of database table with migrations
PEEWEE_MIGRATE_TABLE = 'migratehistory'

# Path to module which contains you applications' Models
# Needed by automatic migrations

# Models which should be ignored in migrations

# Base models class
# Use `db.Model` as your models' base class for automatically DB binding
PEEWEE_MODELS_CLASS = <flask_pw.Model>

# Don't connect to db when request starts and close when it ends automatically


import peewee as pw
from flask import Flask

from flask_pw import Peewee

app = Flask(__name__)

app.config['PEEWEE_DATABASE_URI'] = 'sqlite:///:memory:'

db = Peewee(app)

class User(db.Model):

    name = pw.CharField(255)
    title = pw.CharField(127, null=True)
    active = pw.BooleanField(default=True)
    rating = pw.IntegerField(default=0)

def update(user, created=False):
    if created:
        # Do something


If you use Flask-Script just add ‘db’ command to your manager:

manager = Manager(create_app)
manager.add_command('db', db.manager)

And use db create, db migrate and db rollback commands.

If you use Flask >= 0.11 connect the plugin’s command to your CLI:

pw = Peewee(app)
app.cli.add_command(pw.cli, 'db')
if __name__ == '__main__':
    with app.app_context():


Just add flask_pw.debugtoolbar.PeeweeDebugPanel to Flask-Debugtoolbar panels in your application’s configuration:


    # Add the Peewee panel


Bug tracker

If you have any suggestions, bug reports or annoyances please report them to the issue tracker at


Development of The Flask-pw happens at:


Licensed under a MIT license (See LICENSE)

If you wish to express your appreciation for the project, you are welcome to send a postcard to:

Kirill Klenov
pos. Severny 8-3
MO, Istra, 143500

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for Flask-PW, version 1.1.3
Filename, size File type Python version Upload date Hashes
Filename, size Flask_PW-1.1.3-py2.py3-none-any.whl (10.5 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size Flask-PW-1.1.3.tar.gz (8.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page