Forked from https://github.com/klen/flask-pw , can be used with peewee 3.x.
The Flask-PW3 – 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
Requirements
python 2.7+,3.4+
peewee 3+
Installation
Flask-PW3 should be installed using pip:
pip install flask-pw3
Usage
Settings
Flask-PW3 settings (default values):
# Connection URI
PEEWEE_DATABASE_URI = 'sqlite:///peewee.sqlite'
# Connection params (for example for pgsql: { encoding: 'utf-8' })
PEEWEE_CONNECTION_PARAMS = {}
# 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
PEEWEE_MODELS_MODULE = ''
# Models which should be ignored in migrations
PEEWEE_MODELS_IGNORE = []
# 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
PEEWEE_MANUAL = False
Example
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)
@User.post_save.connect
def update(user, created=False):
if created:
# Do something
Migrations
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():
app.cli()
Flask-Debugtoolbar
Just add flask_pw.debugtoolbar.PeeweeDebugPanel to Flask-Debugtoolbar panels in your application’s configuration:
DEBUG_TB_PANELS = [
'flask_debugtoolbar.panels.versions.VersionDebugPanel',
'flask_debugtoolbar.panels.timer.TimerDebugPanel',
'flask_debugtoolbar.panels.headers.HeaderDebugPanel',
'flask_debugtoolbar.panels.request_vars.RequestVarsDebugPanel',
'flask_debugtoolbar.panels.template.TemplateDebugPanel',
'flask_debugtoolbar.panels.sqlalchemy.SQLAlchemyDebugPanel',
'flask_debugtoolbar.panels.logger.LoggingPanel',
'flask_debugtoolbar.panels.profiler.ProfilerDebugPanel',
# Add the Peewee panel
'flask_pw.flask_debugtoolbar.PeeweeDebugPanel',
]
Enjoy!
Bug tracker
If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/keigohtr/flask-pw3/issues
Contributing
Development of The Flask-pw3 happens at: https://github.com/keigohtr/flask-pw3
Contributors
License
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 Russia
Metadata
Release files for Flask-PW3 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| Flask-PW3-0.0.2.tar.gz | 8.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| Flask_PW3-0.0.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 17.4 kB
Release files / Flask-PW3-0.0.2.tar.gz
| Download URL | Flask-PW3-0.0.2.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b88b5e2a8dee7ab50c0cf88571e711b717da0d2bc4403e1ad4bb96161ddfff3
|
|
BLAKE2b-256 checksum How to use checksums |
70be1dfe7b60b2cc94cc2e5cba03f231db0d8f84a7c2d0db074fc3540ac714d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8
|
Release files / Flask_PW3-0.0.2-py2.py3-none-any.whl
| Download URL | Flask_PW3-0.0.2-py2.py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
a70c0d4e885136c348f30074f03734ce5c3b527905206f4c01ecb0db20648c97
|
|
BLAKE2b-256 checksum How to use checksums |
803bf00ea802b99dbb2a9439126d6b4d03c4a2547d2f40a50fd8e361e4aed587
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8
|