{ "info": { "author": "Diddi Oskarsson", "author_email": "diddi@diddi.se", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# Flask-Seeder\n[![Build Status](https://travis-ci.org/diddi-/flask-seeder.svg?branch=master)](https://travis-ci.org/diddi-/flask-seeder)\n[![Coverage Status](https://coveralls.io/repos/github/diddi-/flask-seeder/badge.svg?branch=master)](https://coveralls.io/github/diddi-/flask-seeder?branch=master)\n\nFlask-Seeder is a Flask extension to help with seeding database with initial data, for example when deploying an application for the first time.\n\nThis extensions primary focus is to help populating data once, for example in a demo application where the database might get wiped over and over but you still want users to have some basic data to play around with.\n\n\n# Installation\n\n```\npip install Flask-Seeder\n```\nThis will install the Flask-Seeder extension and add a `flask seed` subcommand, check it out to see what arguments are supported!\n\n# Seeders\nFlask-Seeder provides a base class `Seeder` that holds a database handle.\nBy subclassing `Seeder` and implementing a `run()` method you get access to the database handle object and can start seeding the database with data.\n\nAll seeders must be somewhere in the `seeds/` directory and inherit from `Seeder` or else they won't be detected.\n\nWhen all seeders have completed (successfully or not), Flask-Seeder will by default commit all changes to the database. This behaviour can be overridden with `--no-commit` or setting environment variable `FLASK_SEEDER_AUTOCOMMIT=0`.\n\n# Faker and Generators\nFlask-Seeder provides a `Faker` class that controls the creation of fake objects, based on real models. By telling `Faker` how to create the objects, you can easily create many different unique objects to help when seeding the database.\n\nThere are different generators that help generate values for the fake objects.\nCurrently supported generators are:\n* Integer: Create a random integer between two values\n* Sequence: Create integers in sequence if called multiple times\n* Name: Create a random name from a list `data/names/names.txt`\n* String: String generation from a pattern\n\nFeel free to roll your own generator by subclassing `Generator` and implement a `generate()` method that return the generated value.\n\n## String generator pattern\nThe `String` generator takes a pattern and produces a string that matches the pattern.\nCurrently the generator pattern is very simple and supports only a handful of operations.\n\n| Pattern | Produces | Description | Example |\n| --| -- | -- | -- |\n| [abc] | String character | Randomly select one of the provided characters | `b` |\n| [a-k] | String character | Randomly select one character from a range | `i` |\n| \\c | String character | Randomly select any alpha character (a-z, A-Z) | `B` |\n| (one\\|two) | String group | Like `[abc]` but works for strings, not just single characters | `one` |\n| \\d | Digit | Randomly select a single digit (0-9) | `8` |\n| {x} | Repeater | Repeat the previous pattern `x` times | `\\d{5}` |\n| {m,n} | Repeater | Repeat the previous pattern `x` times where `x` is anywhere between `m` and `n` | `[0-9]{2,8}` |\n| abc | String literal | No processing, returned as is | `abc` |\n\nPatterns can also be combined to produce more complex strings.\n```\n# Produces something like: abc5586oz\nabc[5-9]{4}\\c[xyz]\n```\n\n# Example usage\nExamples show only relevant snippets of code\n\n**app.py:**\n```python\nfrom flask import Flask\nfrom flask_sqlalchemy import SQLAlchemy\nfrom flask_seeder import FlaskSeeder\n\ndef create_app():\n app = Flask(__name__)\n\n db = SQLAlchemy()\n db.init_app(app)\n\n seeder = FlaskSeeder()\n seeder.init_app(app, db)\n\n return app\n```\n\n**seeds/demo.py:**\n```python\nfrom flask_seeder import Seeder, Faker, generator\n\n# SQLAlchemy database model\nclass User(Base):\n def __init__(self, id_num=None, name=None, age=None):\n self.id_num = id_num\n self.name = name\n self.age = age\n\n def __str__(self):\n return \"ID=%d, Name=%s, Age=%d\" % (self.id_num, self.name, self.age)\n\n# All seeders inherit from Seeder\nclass DemoSeeder(Seeder):\n\n # run() will be called by Flask-Seeder\n def run(self):\n # Create a new Faker and tell it how to create User objects\n faker = Faker(\n cls=User,\n init={\n \"id_num\": generator.Sequence(),\n \"name\": generator.Name(),\n \"age\": generator.Integer(start=20, end=100)\n }\n )\n\n # Create 5 users\n for user in faker.create(5):\n print(\"Adding user: %s\" % user)\n self.db.session.add(user)\n```\n\n***Shell***\n```bash\n$ flask seed run\nRunning database seeders\nAdding user: ID=1, Name=Fancie, Age=76\nAdding user: ID=2, Name=Shela, Age=22\nAdding user: ID=3, Name=Jo, Age=33\nAdding user: ID=4, Name=Laureen, Age=54\nAdding user: ID=5, Name=Tandy, Age=66\nDemoSeeder... [OK]\nCommitting to database!\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/diddi-/flask-seeder", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "Flask-Seeder", "package_url": "https://pypi.org/project/Flask-Seeder/", "platform": "", "project_url": "https://pypi.org/project/Flask-Seeder/", "project_urls": { "Homepage": "https://github.com/diddi-/flask-seeder" }, "release_url": "https://pypi.org/project/Flask-Seeder/0.1a3/", "requires_dist": [ "Flask (>=1.0.2)" ], "requires_python": "", "summary": "Flask extension to seed database through scripts", "version": "0.1a3" }, "last_serial": 5994352, "releases": { "0.1a1": [ { "comment_text": "", "digests": { "md5": "708aaf7f6ab64464cadc80cf8c705e5e", "sha256": "0cb288c84c32854ce63f214a43cb923cff18ca910369a474d4f7724411afef3a" }, "downloads": -1, "filename": "Flask_Seeder-0.1a1-py3-none-any.whl", "has_sig": false, "md5_digest": "708aaf7f6ab64464cadc80cf8c705e5e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5097, "upload_time": "2019-04-19T20:55:49", "url": "https://files.pythonhosted.org/packages/8b/13/9b2687a676e37dbbdb6f848d0c3dde499be5a0541ddb12f9f96a6f0fa801/Flask_Seeder-0.1a1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ea4f91e5dd24cbc670a4714f7c9c95f7", "sha256": "10363ffec9d58851aebc0d3bb23e641dd8cb0054caba57c350b0add9505b03df" }, "downloads": -1, "filename": "Flask-Seeder-0.1a1.tar.gz", "has_sig": false, "md5_digest": "ea4f91e5dd24cbc670a4714f7c9c95f7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4169, "upload_time": "2019-04-19T20:55:51", "url": "https://files.pythonhosted.org/packages/a4/1c/08e4002ee5376256ff6558cad0b81121f039357b7dc332b5d80ff36b877f/Flask-Seeder-0.1a1.tar.gz" } ], "0.1a2": [ { "comment_text": "", "digests": { "md5": "0b8f0ee94b00a2cfa075a9989ec6517e", "sha256": "70a3bbe530bf0bef74924c39e6ceae81fda3220d9e0639a086e60a438bfdc56f" }, "downloads": -1, "filename": "Flask_Seeder-0.1a2-py3-none-any.whl", "has_sig": false, "md5_digest": "0b8f0ee94b00a2cfa075a9989ec6517e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 24395, "upload_time": "2019-04-20T18:30:50", "url": "https://files.pythonhosted.org/packages/df/a1/59605b364dce908a23a42f321ff972f05426624e891c92f58986ecfa3b7d/Flask_Seeder-0.1a2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fcdea641762c1a83f212dff530777c7d", "sha256": "6e13b76f12270ace337f284a26984e3714760a4938fe2bdc8515329a5e24cc52" }, "downloads": -1, "filename": "Flask-Seeder-0.1a2.tar.gz", "has_sig": false, "md5_digest": "fcdea641762c1a83f212dff530777c7d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 27961, "upload_time": "2019-04-20T18:30:51", "url": "https://files.pythonhosted.org/packages/70/81/0c0e6277b0f721286c202ba68366c8df7356fbd6b0b27855a8c2b6c5e158/Flask-Seeder-0.1a2.tar.gz" } ], "0.1a3": [ { "comment_text": "", "digests": { "md5": "36ef1d3ad56b8574433f355bb5b6e119", "sha256": "b7c80fb689765c055e7b516e63a8484e520cb9da9d4462cadb081d8905bf6963" }, "downloads": -1, "filename": "Flask_Seeder-0.1a3-py3-none-any.whl", "has_sig": false, "md5_digest": "36ef1d3ad56b8574433f355bb5b6e119", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 31189, "upload_time": "2019-10-18T08:18:51", "url": "https://files.pythonhosted.org/packages/f1/4c/d11f218e5dc87af2e9192941ac58a78e1111fb9395b1b6a55e7388c47070/Flask_Seeder-0.1a3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ca764026b775b0bbaa498226edbb82f4", "sha256": "5600f900235db7de62c010383ad6918f3a3d678280a7e5f80a4a467d1eb32416" }, "downloads": -1, "filename": "Flask-Seeder-0.1a3.tar.gz", "has_sig": false, "md5_digest": "ca764026b775b0bbaa498226edbb82f4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 33761, "upload_time": "2019-10-18T08:18:53", "url": "https://files.pythonhosted.org/packages/64/fb/9f95aa05cbf6db440490643d69d41ab6515119a58d32f13103eb9923824a/Flask-Seeder-0.1a3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "36ef1d3ad56b8574433f355bb5b6e119", "sha256": "b7c80fb689765c055e7b516e63a8484e520cb9da9d4462cadb081d8905bf6963" }, "downloads": -1, "filename": "Flask_Seeder-0.1a3-py3-none-any.whl", "has_sig": false, "md5_digest": "36ef1d3ad56b8574433f355bb5b6e119", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 31189, "upload_time": "2019-10-18T08:18:51", "url": "https://files.pythonhosted.org/packages/f1/4c/d11f218e5dc87af2e9192941ac58a78e1111fb9395b1b6a55e7388c47070/Flask_Seeder-0.1a3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ca764026b775b0bbaa498226edbb82f4", "sha256": "5600f900235db7de62c010383ad6918f3a3d678280a7e5f80a4a467d1eb32416" }, "downloads": -1, "filename": "Flask-Seeder-0.1a3.tar.gz", "has_sig": false, "md5_digest": "ca764026b775b0bbaa498226edbb82f4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 33761, "upload_time": "2019-10-18T08:18:53", "url": "https://files.pythonhosted.org/packages/64/fb/9f95aa05cbf6db440490643d69d41ab6515119a58d32f13103eb9923824a/Flask-Seeder-0.1a3.tar.gz" } ] }