{"id":15024952,"url":"https://github.com/marktennyson/flask-tortoise","last_synced_at":"2025-04-12T12:52:36.784Z","repository":{"id":62568779,"uuid":"402959228","full_name":"marktennyson/Flask-Tortoise","owner":"marktennyson","description":"Adds asynchronous Tortoise ORM(Like Django-ORM) support for flask app.","archived":false,"fork":false,"pushed_at":"2023-02-17T11:06:40.000Z","size":617,"stargazers_count":7,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T07:36:33.981Z","etag":null,"topics":["async-orm","asynchronous","asyncio","database","flask","flask-async-orm-support","flask-sqlalchemy","flask-tortoise","python","sqlalchemy","tortoise","tortoise-orm"],"latest_commit_sha":null,"homepage":"http://gh.aniketsarkar.site/Flask-Tortoise/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marktennyson.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-04T04:01:17.000Z","updated_at":"2024-12-23T16:15:32.000Z","dependencies_parsed_at":"2025-02-21T13:45:44.931Z","dependency_job_id":null,"html_url":"https://github.com/marktennyson/Flask-Tortoise","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marktennyson%2FFlask-Tortoise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marktennyson%2FFlask-Tortoise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marktennyson%2FFlask-Tortoise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marktennyson%2FFlask-Tortoise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marktennyson","download_url":"https://codeload.github.com/marktennyson/Flask-Tortoise/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571623,"owners_count":21126520,"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":["async-orm","asynchronous","asyncio","database","flask","flask-async-orm-support","flask-sqlalchemy","flask-tortoise","python","sqlalchemy","tortoise","tortoise-orm"],"created_at":"2024-09-24T20:01:16.087Z","updated_at":"2025-04-12T12:52:36.764Z","avatar_url":"https://github.com/marktennyson.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flask-Tortoise\n\n\u003cimg src=\"https://tortoise-orm.readthedocs.io/en/latest/_static/tortoise.png\" height=\"218px\" width=\"388px\"\u003e\u003c/img\u003e\n \n Flask-Tortoise is an extension for Flask that adds support for asynchronous Tortoise-ORM to your application with in-built __migration__ system. It aims to simplify using Tortoise-ORM with Flask by providing useful defaults and extra helpers that make it easier to accomplish common tasks.\n\nTortoise-ORM is one of the best tool to interact with the database asynchronously. It's clean and Django type implementation provides you a better view and understanding of the database ORM system. Also you can use the Pydantic data module to write the error-less code.\n\nThe main aim of __Tortoise-ORM__ is to provide the same service and api like the __Django-ORM__.\n\n### Installing\nInstall and update from PYPI:\n```bash\npip install -U Flask-Tortoise\n```\nInstall from source code:\n```bash\ngit clone https://github.com/marktennyson/Flask-Tortoise\ncd Flask-Tortoise \u0026\u0026 pip install .\n```\n\n### Important links\n__Github Link:__ [https://github.com/marktennyson/Flask-Tortoise](https://github.com/marktennyson/Flask-Tortoise)    \n__Official Documentation:__ [https://marktennyson.github.io/Flask-Tortoise](https://marktennyson.github.io/Flask-Tortoise/)\n\n### Simple Examples for better understanding:\n```python\nfrom flask import Flask, jsonify\nfrom flask_tortoise import Tortoise\nfrom random import choice\n\n\nSTATUSES = [\"New\", \"Old\", \"Gone\"]\n\napp:\"Flask\" = Flask(__name__)\napp.config['TORTOISE_ORM_DATABASE_URI'] = 'sqlite://db.sqlite3'\n\ndb:\"Tortoise\" = Tortoise(app)\n\n\nclass Users(db.Model):\n    id = db.IntField(pk=True)\n    status = db.CharField(20)\n\n    def __str__(self):\n        return f\"User {self.id}: {self.status}\"\n\n\nclass Workers(db.Model):\n    id = db.IntField(pk=True)\n    status = db.CharField(20)\n\n    def __str__(self):\n        return f\"Worker {self.id}: {self.status}\"\n\n@app.get(\"/\")\nasync def list_all():\n    users = await Users.all()\n    workers = await Workers.all()\n    return jsonify(\n        {\"users\": [str(user) for user in users], \"workers\": [str(worker) for worker in workers]}\n    )\n\n\n@app.get(\"/user\")\nasync def add_user():\n    user = await Users.create(status=choice(STATUSES))  # nosec\n    return str(user)\n\n\n@app.get(\"/worker\")\nasync def add_worker():\n    worker = await Workers.create(status=choice(STATUSES))  # nosec\n    return str(worker)\n\n@app.get(\"/get-worker\")\nasync def get_worker():\n    worker:\"Workers\" = await Workers.get(id=1)\n    return str(worker.status)\n\n\nif __name__ == '__main__':\n    app.run(debug=True, port=8080)\n```\n\n#### If you save your models into a separate file than you have mention the file name on app config:\n\nlet's assume you have stores all of your models at `models.py` file.\n##### models.py file\n```python\nfrom flask_tortoise import Tortoise, Model, fields\n\ndb:\"Tortoise\" = Tortoise()\n\n\nclass Users(db.Model):\n    id = db.IntField(pk=True)\n    status = db.CharField(20)\n\n    def __str__(self):\n        return f\"User {self.id}: {self.status}\"\n\n\nclass Workers(db.Model):\n    id = db.IntField(pk=True)\n    status = db.CharField(20)\n\n    def __str__(self):\n        return f\"Worker {self.id}: {self.status}\"\n```\n\n##### app.py file:\n```python\nfrom flask import Flask, jsonify\nfrom models import *\nfrom random import choice\n\n\nSTATUSES = [\"New\", \"Old\", \"Gone\"]\n\napp:\"Flask\" = Flask(__name__)\napp.config['TORTOISE_ORM_DATABASE_URI'] = 'sqlite://db.sqlite3'\napp.config['TORTOISE_ORM_MODELS'] = \"models\" # if you have more than one models file then : [\"models_1\", \"models_2\", \"models_3\"]\n\ndb.init_app(app)\n\n@app.get(\"/\")\nasync def list_all():\n    users = await Users.all()\n    workers = await Workers.all()\n    return jsonify(\n        {\"users\": [str(user) for user in users], \"workers\": [str(worker) for worker in workers]}\n    )\n\n\n@app.get(\"/user\")\nasync def add_user():\n    user = await Users.create(status=choice(STATUSES))  # nosec\n    return str(user)\n\n\n@app.get(\"/worker\")\nasync def add_worker():\n    worker = await Workers.create(status=choice(STATUSES))  # nosec\n    return str(worker)\n\n@app.get(\"/get-worker\")\nasync def get_worker():\n    worker:\"Workers\" = await Workers.get(id=1)\n    return str(worker.status)\n\n\nif __name__ == '__main__':\n    app.run(debug=True, port=8080)\n```\n### Contributing:\nWe welcome all types of contributions. If you face any issue while using this module then please let us know by creating a github issue on the official github repo. If you have the solution for the issue raised by you or somebody else then please fork this repo and create a pull request with the main branch.\n\n##### How to run this project on local machine:\n1. Fork this repo.\n2. Clone this repo on your local machine.\n3. create a virtual environment using python `virtualenv` module and activate it.\n4. now run `python setup.py install`.\n5. the above command will install the latest dev version of `Flask-Tortoise` on the virtual environment.\n\n### Contributor List:\n\u003ca href=\"https://github.com/marktennyson/Flask-Tortoise/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contrib.rocks/image?repo=marktennyson/Flask-Tortoise\" /\u003e\n\u003c/a\u003e\n\n### License\n\n[MIT](https://github.com/marktennyson/flask-mailing/blob/development/LICENSE)\n\nCopyright (c) 2023 Aniket Sarkar(aniketsarkar@yahoo.com)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarktennyson%2Fflask-tortoise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarktennyson%2Fflask-tortoise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarktennyson%2Fflask-tortoise/lists"}