sqlalchemy_seed
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.
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sqlalchemy_seed-0.3.0.tar.gz | 4.5 kB | Without provenance | Details for sqlalchemy_seed-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sqlalchemy_seed-0.3.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for sqlalchemy_seed-0.3.0-py2.py3-none-any.whl |
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
|
Security for sqlalchemy_seed 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.