Skip to main content

peewee_seed is simple data seeder using peewee.

Project description

# peewee_seed
peewee_seed is a seed library which provides initial data to database using peewee.
With reference to the [Django fixture](

[![PyPI version](](
## usage

### simple seeds
- file envs
``` yaml
# accounts.yaml
- model : myapp.models.Account
id: 1
first_name: John
last_name: Smith
age: 20
from peewee import CharField
from peewee import IntegerField
from peewee import Model
from peewee import SqliteDatabase

database = SqliteDatabase(":memory:", pragmas={"foregin_keys": 1})

class BaseModel(Model):
class Meta(object):
database = database

class Account(BaseModel):
first_name = CharField(null=False)
last_name = CharField(null=False)
age = IntegerField(null=True)
- seeds entry file
``` python
from peewee_seeds import PeeweeSeed
from myapp.models import database

def main():
path = '/path/to/fixtures'

# seeds instance
seeds = PeeweeSeed(database, path, ['accounts.yaml'])

# load fixture for create table

# load fixture for db input

if __name__ == '__main__':
- Run command

### other example

from peewee_seed import PeeweeSeed
from myapp.models import database

# seeds instance
seeds = PeeweeSeed()

# set path

# set use fixture name
seeds.set_fixture_files(['accounts.yaml', 'pictures.yaml'])

# loading fixture file data
fixtures_row_data = seeds.load_fixture_files()

# fixture purification
fields, models_namelist = seeds.load_fixture(fixtures_row_data[0])

# fixtures purification
fields, models_namelist = seeds.load_fixtures(fixtures_row_data)

# set database session

# base on fixtures, create tables

# fixtures data to db input

# base on fixtures, drop tables

### direct inputdata seed
``` python
# body is dict data
# create & seed
seed = PeeweeSeed(db)
_, models = seed.load_fixtures([body])


# body is modelpath(same to fixtures)
# drop
seed = PeeweeSeed(db)

models = body["models"]

#### error: Foreign key constraint


# seed
seed.db_data_input([body], foreign_key_checks=True)

# db drop
seed.drop_table_all(models, foreign_key_checks=True)


Project details

Download files

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

Built Distribution

peewee_seed-0.1.8-py3-none-any.whl (5.1 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page