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.

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.

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


Download files

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

Source Distribution

Flask-PW-0.0.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

Flask_PW-0.0.1-py2.py3-none-any.whl (7.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file Flask-PW-0.0.1.tar.gz.

File metadata

  • Download URL: Flask-PW-0.0.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Flask-PW-0.0.1.tar.gz
Algorithm Hash digest
SHA256 1384a3a2597120abeda2d9947d57da2dbe7935bd884b9d9bbf2be8f7647d13cc
MD5 d6fe3ddd8e498038f5d0ad7d90df822d
BLAKE2b-256 8e97a77cc6c3fe8d5900628cb0a78a4819b8c11f35399485682c4a73cf3f67ed

See more details on using hashes here.

File details

Details for the file Flask_PW-0.0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for Flask_PW-0.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 72512a594f4ce70332aaf726981de38654bfd7499986d142b51da37a819ddf5b
MD5 d0ba1ddc8090afd2dc2ceed9406853dd
BLAKE2b-256 84eee4473ec22b60c1d702c6a0c3ccf6b7f57b6ae185693e33e7b95d0662932c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page