Flask extension to seed database through scripts
Project description
Flask-Seeder
Flask-Seeder is a Flask extension to help with seeding database with initial data, for example when deploying an application for the first time.
This extensions primary focus is to help populating data once, for example in a demo application where the database might get wiped over and over but you still want users to have some basic data to play around with.
Installation
pip install Flask-Seeder
This will install the Flask-Seeder extension and add a flask seed subcommand, check it out to see what arguments are supported!
Seeders
Flask-Seeder provides a base class Seeder that holds a database handle.
By subclassing Seeder and implementing a run() method you get access to the database handle object and can start seeding the database with data.
All seeders must be somewhere in the seeds/ directory and inherit from Seeder or else they won't be detected.
Example usage
Examples show only relevant snippets of code
app.py:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_seeder import FlaskSeeder
create_app():
app = Flask(__name__)
db = SQLAlchemy()
db.init_app(app)
seeder = FlaskSeeder()
seeder.init_app(app, db)
return app
seeds/demo.py:
from flask_seeder import Seeder
# All seeders inherit from Seeder
class DemoSeeder(Seeder):
# run() will be called by Flask-Seeder after instantiating the class
def run(self):
self.db.session.add(...) # Standard SQLAlchemy add
self.db.session.commit()
Shell
$ flask seed run
Running database seeders
DemoSeeder... [OK]
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file Flask-Seeder-0.1a1.tar.gz.
File metadata
- Download URL: Flask-Seeder-0.1a1.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10363ffec9d58851aebc0d3bb23e641dd8cb0054caba57c350b0add9505b03df
|
|
| MD5 |
ea4f91e5dd24cbc670a4714f7c9c95f7
|
|
| BLAKE2b-256 |
a41c08e4002ee5376256ff6558cad0b81121f039357b7dc332b5d80ff36b877f
|
File details
Details for the file Flask_Seeder-0.1a1-py3-none-any.whl.
File metadata
- Download URL: Flask_Seeder-0.1a1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cb288c84c32854ce63f214a43cb923cff18ca910369a474d4f7724411afef3a
|
|
| MD5 |
708aaf7f6ab64464cadc80cf8c705e5e
|
|
| BLAKE2b-256 |
8b139b2687a676e37dbbdb6f848d0c3dde499be5a0541ddb12f9f96a6f0fa801
|