{"id":21013395,"url":"https://github.com/heavenshell/py-sqlalchemy_seed","last_synced_at":"2025-05-15T04:34:16.204Z","repository":{"id":17345702,"uuid":"81715191","full_name":"heavenshell/py-sqlalchemy_seed","owner":"heavenshell","description":"Simple data seeder using SQLAlchemy.","archived":false,"fork":false,"pushed_at":"2022-08-08T19:02:39.000Z","size":75,"stargazers_count":27,"open_issues_count":4,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-09-14T22:24:23.598Z","etag":null,"topics":["python","sqlalchemy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/heavenshell.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-12T09:19:30.000Z","updated_at":"2024-04-19T09:27:24.000Z","dependencies_parsed_at":"2022-07-29T08:19:28.404Z","dependency_job_id":null,"html_url":"https://github.com/heavenshell/py-sqlalchemy_seed","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heavenshell%2Fpy-sqlalchemy_seed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heavenshell%2Fpy-sqlalchemy_seed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heavenshell%2Fpy-sqlalchemy_seed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heavenshell%2Fpy-sqlalchemy_seed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heavenshell","download_url":"https://codeload.github.com/heavenshell/py-sqlalchemy_seed/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224944579,"owners_count":17396254,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python","sqlalchemy"],"created_at":"2024-11-19T09:42:12.203Z","updated_at":"2024-11-19T09:42:12.745Z","avatar_url":"https://github.com/heavenshell.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"sqlalchemy_seed\n----------------\n\n.. image:: https://github.com/heavenshell/py-sqlalchemy_seed/workflows/build/badge.svg\n     :target: https://github.com/heavenshell/py-sqlalchemy_seed/actions?query=workflow%3Abuild\n.. image:: https://pyup.io/repos/github/heavenshell/py-sqlalchemy_seed/python-3-shield.svg\n     :target: https://pyup.io/repos/github/heavenshell/py-sqlalchemy_seed/\n     :alt: Python 3\n.. image:: https://pyup.io/repos/github/heavenshell/py-sqlalchemy_seed/shield.svg\n     :target: https://pyup.io/repos/github/heavenshell/py-sqlalchemy_seed/\n     :alt: Updates\n\n`sqlalchemy_seed` is a seed library which provides initial data to database using SQLAlchemy.\n\n`sqlalchemy_seed` is similar to `Django fixtures \u003chttps://docs.djangoproject.com/ja/1.10/howto/initial-data/\u003e`_.\n\nInstallation\n============\n\n.. code::\n\n  pip install sqlalchemy_seed\n\nAdding seed\n===========\n\n.. code::\n\n  /myapp\n    __init__.py\n    models.py\n    /fixtures\n      accounts.yaml\n\nModel file.\n\n.. code:: python\n\n  # -*- coding: utf-8 -*-\n\n  from sqlalchemy import create_engine\n  from sqlalchemy.exc import OperationalError\n  from sqlalchemy.ext.declarative import declarative_base\n  from sqlalchemy.orm import scoped_session, sessionmaker, relationship\n  engine = create_engine('sqlite://', convert_unicode=True)\n\n  Base = declarative_base()\n  Base.metadata.bind = engine\n  Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)\n  session = scoped_session(Session)\n\n  class Account(Base):\n      __tablename__ = 'accounts'\n\n      id = Column(Integer, primary_key=True)\n      first_name = Column(String(100), nullable=False)\n      last_name = Column(String(100), nullable=False)\n      age = Column(Integer(), nullable=True)\n\n\nSeed code.\n\n.. code:: python\n\n  # -*- coding: utf-8 -*-\n\n  from sqlalchemy_seed import (\n      create_table,\n      drop_table,\n      load_fixtures,\n      load_fixture_files,\n  )\n  from myapp.models import Base, session\n\n\n  def main():\n      path = '/path/to/fixtures'\n      fixtures = load_fixture_files(path, ['accounts.yaml'])\n      load_fixtures(session, fixtures)\n\n\n  if __name__ == '__main__':\n      main()\n\nSeed file.\n\n.. code::\n\n  - model: myapp.models.Account\n    id: 1\n    fields:\n      first_name: John\n      last_name: Lennon\n      age: 20\n\n  - model: myapp.models.Account\n    id: 2\n    fields:\n      first_name: Paul\n      last_name: McCartney\n      age: 21\n\n\nUpdate seed\n===========\n\nIf you want idempotent, you can describe seed like followings.\n\nSeed file.\n\n.. code::\n\n  - model: myapp.models.Account\n    fields:\n      id: 1\n      first_name: John\n      last_name: Lennon\n      age: 20\n\n  - model: myapp.models.Account\n    fields:\n      id: 2\n      first_name: Paul\n      last_name: McCartney\n      age: 21\n\nLICENSE\n=======\nNEW BSD LICENSE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheavenshell%2Fpy-sqlalchemy_seed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheavenshell%2Fpy-sqlalchemy_seed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheavenshell%2Fpy-sqlalchemy_seed/lists"}