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
Requirements
python 2.7+,3.4+
Installation
Flask-PW should be installed using pip:
pip install flask-pw
Usage
Settings
Flask-PW 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_MIGRATIONS = 'migrations' # 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.
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/klen/flask-pw/issues
Contributing
Development of The Flask-pw happens at: https://github.com/klen/flask-pw
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Flask-PW-0.2.0.tar.gz
.
File metadata
- Download URL: Flask-PW-0.2.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e46e10fdf334bea0f204054123752f3a1bb7c79d557a3b23f8c9244d7b1f017 |
|
MD5 | 02b231a37f063ab5557c04f7a0a7b3d0 |
|
BLAKE2b-256 | 199db10ab235dda0b3df264b945928679466bb3010ee905ed1aede30fb300752 |
File details
Details for the file Flask_PW-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: Flask_PW-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 271bdc1ebe76951e8d08d24e73e7756ba42a2da3cc66dbadf267e0266874532a |
|
MD5 | e5401972fa6793a37ace157b8203a06d |
|
BLAKE2b-256 | a9d1543992c25de834eaaf231264f77be46974f7abb81e740dd35eeda68a3438 |