Skip to main content
https://travis-ci.org/heavenshell/py-sqlalchemy_seed.svg?branch=master Python 3 Updates

sqlalchemy_seed is a seed library which provides initial data to database using SQLAlchemy.

sqlalchemy_seed is similar to Django fixtures.

Installation

pip install sqlalchemy_seed

Adding seed

/myapp
  __init__.py
  models.py
  /fixtures
    accounts.yaml

Model file.

# -*- coding: utf-8 -*-

from sqlalchemy import create_engine
from sqlalchemy.exc import OperationalError
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker, relationship
engine = create_engine('sqlite://', convert_unicode=True)

Base = declarative_base()
Base.metadata.bind = engine
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)
session = scoped_session(Session)

class Account(Base):
    __tablename__ = 'accounts'

    id = Column(Integer, primary_key=True)
    first_name = Column(String(100), nullable=False)
    last_name = Column(String(100), nullable=False)
    age = Column(Integer(), nullable=True)

Seed code.

# -*- coding: utf-8 -*-

from sqlalchemy_seed import (
    create_table,
    drop_table,
    load_fixtures,
    load_fixture_files,
)
from myapp.models import Base, session


def main():
    path = '/path/to/fixtures'
    fixtures = load_fixture_files(path, ['accounts.yaml'])
    load_fixtures(session, fixtures)


if __name__ == '__main__':
    main()

Seed file.

- model: myapp.models.Account
  id: 1
  fields:
    first_name: John
    last_name: Lennon
    age: 20

- model: myapp.models.Account
  id: 2
  fields:
    first_name: Paul
    last_name: McCartney
    age: 21

LICENSE

NEW BSD LICENSE.

Release files for sqlalchemy_seed 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlalchemy_seed 0.3.0
File Size Uploaded
sqlalchemy_seed-0.3.0.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlalchemy_seed 0.3.0
File Interpreter ABI Platform
sqlalchemy_seed-0.3.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 10.1 kB

Release files / sqlalchemy_seed-0.3.0.tar.gz

Download URL sqlalchemy_seed-0.3.0.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
be89813140fa4fe39d4121d364f9c00090c9509c5ec310bfb9579591fe923a95
BLAKE2b-256 checksum
How to use checksums
2fe1ab53ae4d7d9467ee8d17355f4e9f9160662feef68b1fd1dfbf52335224ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Release files / sqlalchemy_seed-0.3.0-py2.py3-none-any.whl

Download URL sqlalchemy_seed-0.3.0-py2.py3-none-any.whl
Size 5.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
7e241331cfd20a65b79b24c66b4d1a1911a13bfb9aac76f84e60b100c88b1930
BLAKE2b-256 checksum
How to use checksums
22d2c55b8d416e94b771f0c7b0616292f3340e603e82a1e7af5753d280985c21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.2

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page