{ "info": { "author": "Eduardo Naufel Schettino", "author_email": "schettino72@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6" ], "description": "sqla\\_yaml\\_fixtures\n====================\n\nLoad YAML data fixtures for SQLAlchemy\n\n.. image:: https://img.shields.io/pypi/v/sqla_yaml_fixtures.svg\n :target: https://pypi.python.org/pypi/sqla_yaml_fixtures\n\n.. image:: https://img.shields.io/pypi/l/sqla_yaml_fixtures.svg\n :target: https://pypi.python.org/pypi/sqla_yaml_fixtures\n\n.. image:: https://img.shields.io/pypi/pyversions/sqla_yaml_fixtures.svg\n :target: https://pypi.python.org/pypi/sqla_yaml_fixtures\n\n.. image:: https://api.shippable.com/projects/5945f25f4fdc63070017442d/badge?branch=master\n :target: https://app.shippable.com/github/schettino72/sqla_yaml_fixtures\n\n.. image:: https://api.shippable.com/projects/5945f25f4fdc63070017442d/coverageBadge?branch=master\n :target: https://app.shippable.com/github/schettino72/sqla_yaml_fixtures\n\nThis package allows you to define some data in YAML and load them into a\nDB. The yaml data should correspond to SQLAlchemy declarative mappers.\n\nExample:\n\n.. code:: yaml\n\n - User:\n - __key__: joey\n username: joey\n email: joey@example.com\n profile:\n name: Jeffrey\n\n - __key__: dee\n username: deedee\n email: deedee@example.com\n\n - Profile:\n - user: dee\n name: Douglas\n\n - Group:\n - name: Ramones\n members: [joey.profile, dee.profile]\n\n- The root of YAML contains a *sequence* of ``mapper names`` e.g. ``- User``, ``- Profile`` etc\n- The order of these names should follow relationship dependencies\n- Every name should contain a *sequence* of instances\n- Each instance is a *mapping* of *attribute* -> *value*\n- the attributes are taken from the mapper ``__init__()`` (usually an\n attributes maps to a column)\n- The special field ``__key__`` can be used to identify this instnace\n in a relationship reference e.g. The ``Profile.user``\n- Note that any ``__key__`` MUST be globally **unique**\n- In a *to-one* relationship the data can be directly nested in the\n parent data definition\n- References can access attributes using a *dot* notation, e.g.\n ``joey.profile``\n- *to-many* relationships can be added as a list of references\n\nThe mapper definition for this example is in the `test file`_.\n\nInstallation\n------------\n\n``pip install sqla-yaml-fixtures``\n\n\nAPI\n---\n\nThis module expose a single function\n``load(ModelBase, session, fixture_text)``\n\nWhere:\n\n- ``ModelBase`` is SQLAlchemy declarative base\n- ``session`` is SQLAlchemy session\n- ``fixture_text`` is a string containg the YAML fixtures\n\n.. code:: python\n\n from sqlalchemy import create_engine\n from sqlalchemy import Column, Integer, String\n from sqlalchemy.ext.declarative import declarative_base\n from sqlalchemy.orm import Session\n\n import sqla_yaml_fixtures\n\n BaseModel = declarative_base()\n\n class User(BaseModel):\n __tablename__ = 'user'\n id = Column(Integer, primary_key=True)\n username = Column(String(150), nullable=False, unique=True)\n email = Column(String(254), unique=True)\n\n\n def main():\n engine = create_engine('sqlite://')\n BaseModel.metadata.create_all(engine)\n connection = engine.connect()\n session = Session(bind=connection)\n\n fixture = \"\"\"\n - User:\n - username: deedee\n email: deedee@example.com\n - username: joey\n email: joey@example.commit\n \"\"\"\n sqla_yaml_fixtures.load(BaseModel, session, fixture)\n\n print('\\n'.join(u.username for u in session.query(User).all()))\n\n if __name__ == '__main__':\n main()\n\n\nNote: the `load()` function performs a `session.commit()`.\n\n`load()` returns an instance of `Store`. Using this object `get()` method you can passing a `key` as argument you get a reference to the object added into the database. This is useful to easily get attributes that are generated by the database.\n\n.. code:: python\n\n store = sqla_yaml_fixtures.load(BaseModel, session, fixture)\n my_obj = store.get('dee')\n print('Created object id: {}'.format(my_obj.id))\n\n\n\nCommand Line\n------------\n\nFor basic usage there is also command line. Example::\n\n $ python -m sqla_yaml_fixtures --db-url sqlite:///dev.db --db-base mypkg.models:Base --reset-db --alembic-stamp fixture.yaml\n\n\nAll available options::\n\n $ python -m sqla_yaml_fixtures --help\n usage: sqla_yaml_fixtures [-h] --db-base DB_BASE --db-url DB_URL [--yes]\n [--reset-db] [--alembic-stamp] [--jinja2]\n FILE [FILE ...]\n\n load fixtures from yaml file into DB\n\n positional arguments:\n FILE YAML file with DB fixtures\n\n optional arguments:\n -h, --help show this help message and exit\n --db-base DB_BASE SQLAlchemy Base class with schema metadata in the format\n my_package.my_module:MyClass\n --db-url DB_URL Database URL in the format\n dialect+driver://username:password@host:port/database\n --yes Do NOT ask for confirmation before applying fixtures\n --reset-db Drop DB schema and data and re-create schema before\n loading fixtures\n --alembic-stamp Perform `alembic stamp head`\n --jinja2 load fixture files as jinja2 templates\n\n\n\n.. _test file: https://github.com/schettino72/sqla_yaml_fixtures/blob/master/tests/test_sqla_yaml_fixtures.py", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/schettino72/sqla_yaml_fixtures", "keywords": "fixture,sqlalchemy", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "sqla-yaml-fixtures", "package_url": "https://pypi.org/project/sqla-yaml-fixtures/", "platform": "", "project_url": "https://pypi.org/project/sqla-yaml-fixtures/", "project_urls": { "Homepage": "https://github.com/schettino72/sqla_yaml_fixtures" }, "release_url": "https://pypi.org/project/sqla-yaml-fixtures/0.9.1/", "requires_dist": null, "requires_python": "", "summary": "Load YAML data fixtures for SQLAlchemy", "version": "0.9.1" }, "last_serial": 4105581, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "4d741af0fa36933710b22bd1c54f6249", "sha256": "199c6edc10f537c930ed3881f42d5113f55b63cc093aad34760695c2ffa2da4e" }, "downloads": -1, "filename": "sqla_yaml_fixtures-0.1.0.tar.gz", "has_sig": false, "md5_digest": "4d741af0fa36933710b22bd1c54f6249", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2457, "upload_time": "2017-06-14T14:17:37", "url": "https://files.pythonhosted.org/packages/c6/a0/c3d52e4b3678a2a1e58e277a4247b8d80a3149b3de5992770b75559b205e/sqla_yaml_fixtures-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "d9707d1759ba517d121ffddd2f7f43be", "sha256": "04dfad191627e8a5a582bfa0f365a362c6440b2b0061c37813873b44461c84b3" }, "downloads": -1, "filename": "sqla_yaml_fixtures-0.1.1.tar.gz", "has_sig": false, "md5_digest": "d9707d1759ba517d121ffddd2f7f43be", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3527, "upload_time": "2017-06-14T14:42:28", "url": "https://files.pythonhosted.org/packages/42/41/7e0cf6d7fcdf1511bf671d088ac28e3f8679a5c795650358dae89efb65d3/sqla_yaml_fixtures-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "cf2143ed3158b31121751e62b24511ab", "sha256": "91930fccd36e54f129675a9598355f20bd5ab6a9e90a7ea0210c7ec55eaa0250" }, "downloads": -1, "filename": "sqla_yaml_fixtures-0.1.2.tar.gz", "has_sig": false, "md5_digest": "cf2143ed3158b31121751e62b24511ab", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3917, "upload_time": "2017-06-14T14:47:25", "url": "https://files.pythonhosted.org/packages/6c/7d/bd0da5a072d68f6043e57551b9e39548268bf11f78432b719998e7b23595/sqla_yaml_fixtures-0.1.2.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "b8de5bb7fd36a7815aa28c0b1843171b", "sha256": "684ad4f3fd88dee352db795c9afafdb35e27c3f80d4bae7a04cfc39ab9a02b2d" }, "downloads": -1, "filename": "sqla_yaml_fixtures-0.2.0.tar.gz", "has_sig": false, "md5_digest": "b8de5bb7fd36a7815aa28c0b1843171b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4975, "upload_time": "2017-06-24T12:41:24", "url": "https://files.pythonhosted.org/packages/98/2b/f14f55266f3723a5a86c9b7c56c4a5a639788d2d93b0ec081f59181b9a70/sqla_yaml_fixtures-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "dcc1083d08d58db0c6d5a788c540adfc", "sha256": "bea95d4c4b9ae8635f1154a743d3520e2a7fcb9f778b3aeb5a7c741f724191f3" }, "downloads": -1, "filename": "sqla_yaml_fixtures-0.3.0.tar.gz", "has_sig": false, "md5_digest": "dcc1083d08d58db0c6d5a788c540adfc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5175, "upload_time": "2017-06-28T14:38:51", "url": "https://files.pythonhosted.org/packages/ca/37/31c70d0f0f3333ce472f0abdbf416c5905b33b0f2c6319d406937b63cdc6/sqla_yaml_fixtures-0.3.0.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "bf67e6882bcf2e862e8e9336ba4d7fca", "sha256": "375cb3f1f96e751baced1be6d99f705e5ea0a322630851bba58bb89c8f9834e6" }, "downloads": -1, "filename": "sqla_yaml_fixtures-0.4.0.tar.gz", "has_sig": false, "md5_digest": "bf67e6882bcf2e862e8e9336ba4d7fca", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5260, "upload_time": "2017-07-17T16:20:32", "url": "https://files.pythonhosted.org/packages/72/d7/895f3b17bf19be7f230c5804023bdc0b51849ca6ce4ab36b1cd9627450c7/sqla_yaml_fixtures-0.4.0.tar.gz" } ], "0.5.0": [ { "comment_text": "", "digests": { "md5": "103ea72f340d348c6e3f4f00e8a82dd7", "sha256": "b942f4ab37cede61510ed447a25cdf6d0e3cf0548d6cdba85e773dec2ef6441f" }, "downloads": -1, "filename": "sqla_yaml_fixtures-0.5.0.tar.gz", "has_sig": false, "md5_digest": "103ea72f340d348c6e3f4f00e8a82dd7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5318, "upload_time": "2017-07-17T19:23:12", "url": "https://files.pythonhosted.org/packages/5c/48/2130bef5b8ecaf4952a37100a502e52fa2658f5bd21b73f6c4676d15f3d1/sqla_yaml_fixtures-0.5.0.tar.gz" } ], "0.6.0": [ { "comment_text": "", "digests": { "md5": "f2253196d4a62419b54325f7758cdb42", "sha256": "c737320e4ad530eb9235245b1944e70acac8e9ac5d16c7461eddb6c55bc64ea7" }, "downloads": -1, "filename": "sqla_yaml_fixtures-0.6.0.tar.gz", "has_sig": false, "md5_digest": "f2253196d4a62419b54325f7758cdb42", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6390, "upload_time": "2017-08-24T13:27:09", "url": "https://files.pythonhosted.org/packages/e4/22/93b73394addd20cf100b0ad29290e1d0f53808ba0c0938ecc7b22e48f383/sqla_yaml_fixtures-0.6.0.tar.gz" } ], "0.7.0": [ { "comment_text": "", "digests": { "md5": "28d0ebf70ea5752161b2638de17acf18", "sha256": "9ba38b1da63cf71e12e4ce39f870de59992b1bce4f4a115f0c8552be0e8d7a49" }, "downloads": -1, "filename": "sqla_yaml_fixtures-0.7.0.tar.gz", "has_sig": false, "md5_digest": "28d0ebf70ea5752161b2638de17acf18", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6647, "upload_time": "2017-09-01T23:48:09", "url": "https://files.pythonhosted.org/packages/24/6a/2d446895bcc875915cefb76171fae34ab8e8b1db8ee1a145858143da7b70/sqla_yaml_fixtures-0.7.0.tar.gz" } ], "0.8.0": [ { "comment_text": "", "digests": { "md5": "7a2aa012818f258455868f82e9e7da3d", "sha256": "e2f6cdc5947f8b9d993cefbee7c73bbcdea2e43c4359d5eaed66d47336a59dab" }, "downloads": -1, "filename": "sqla_yaml_fixtures-0.8.0.tar.gz", "has_sig": false, "md5_digest": "7a2aa012818f258455868f82e9e7da3d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6723, "upload_time": "2018-01-03T04:20:56", "url": "https://files.pythonhosted.org/packages/86/c9/b8a9d8a6c76421b61134969240280e4bd8c3139fb9f93119b8d865bdd4fd/sqla_yaml_fixtures-0.8.0.tar.gz" } ], "0.9.0": [ { "comment_text": "", "digests": { "md5": "daf9925535ac9759aa6be8f1f84d050d", "sha256": "9635b59437113a1315db908e1c5de1cb9ce1d921b9116581b15dce3ad78a0e12" }, "downloads": -1, "filename": "sqla_yaml_fixtures-0.9.0.tar.gz", "has_sig": false, "md5_digest": "daf9925535ac9759aa6be8f1f84d050d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7106, "upload_time": "2018-07-24T15:04:51", "url": "https://files.pythonhosted.org/packages/c7/2a/4beda1b1bfc5e90efe3aabee10e76209b67b6ba591a8b054788d1bb7c1af/sqla_yaml_fixtures-0.9.0.tar.gz" } ], "0.9.1": [ { "comment_text": "", "digests": { "md5": "fb99b589ffd9187c8f825ea4c82812c7", "sha256": "56b8e1f9ef906309af685087d9b8ff4dfe38d0aef8bddf8335eec39aeecc13dc" }, "downloads": -1, "filename": "sqla_yaml_fixtures-0.9.1.tar.gz", "has_sig": false, "md5_digest": "fb99b589ffd9187c8f825ea4c82812c7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7132, "upload_time": "2018-07-26T17:36:33", "url": "https://files.pythonhosted.org/packages/b7/02/7bf1f4124788050c2331246f02d5a42bff0fba2a31d0fa197c2e174753a8/sqla_yaml_fixtures-0.9.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "fb99b589ffd9187c8f825ea4c82812c7", "sha256": "56b8e1f9ef906309af685087d9b8ff4dfe38d0aef8bddf8335eec39aeecc13dc" }, "downloads": -1, "filename": "sqla_yaml_fixtures-0.9.1.tar.gz", "has_sig": false, "md5_digest": "fb99b589ffd9187c8f825ea4c82812c7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7132, "upload_time": "2018-07-26T17:36:33", "url": "https://files.pythonhosted.org/packages/b7/02/7bf1f4124788050c2331246f02d5a42bff0fba2a31d0fa197c2e174753a8/sqla_yaml_fixtures-0.9.1.tar.gz" } ] }