Skip to main content

Flask extension to seed database through scripts

Project description

Flask-Seeder

Build Status Coverage Status

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


Download files

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

Source Distribution

Flask-Seeder-0.1a1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Flask_Seeder-0.1a1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

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

Hashes for Flask-Seeder-0.1a1.tar.gz
Algorithm Hash digest
SHA256 10363ffec9d58851aebc0d3bb23e641dd8cb0054caba57c350b0add9505b03df
MD5 ea4f91e5dd24cbc670a4714f7c9c95f7
BLAKE2b-256 a41c08e4002ee5376256ff6558cad0b81121f039357b7dc332b5d80ff36b877f

See more details on using hashes here.

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

Hashes for Flask_Seeder-0.1a1-py3-none-any.whl
Algorithm Hash digest
SHA256 0cb288c84c32854ce63f214a43cb923cff18ca910369a474d4f7724411afef3a
MD5 708aaf7f6ab64464cadc80cf8c705e5e
BLAKE2b-256 8b139b2687a676e37dbbdb6f848d0c3dde499be5a0541ddb12f9f96a6f0fa801

See more details on using hashes here.

Supported by

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