sqlalchemyseed
Sqlalchemy seeder that supports nested relationships.
Supported file types
- json
- yaml
- csv
Installation
Default installation
pip install sqlalchemyseed
Quickstart
main.py
from sqlalchemyseed import load_entities_from_json
from sqlalchemyseed import Seeder
from db import session
# load entities
entities = load_entities_from_json('data.json')
# Initializing Seeder
seeder = Seeder(session)
# Seeding
seeder.seed(entities)
# Committing
session.commit() # or seeder.session.commit()
data.json
{
"model": "models.Person",
"data": [
{
"name": "John March",
"age": 23
},
{
"name": "Juan Dela Cruz",
"age": 21
}
]
}