# Tortoise-API
###### Simplest fastest minimal REST API CRUD generator for Tortoise ORM models.
Fully async Zero config One line ASGI app
#### Requirements
- Python >= 3.9
### INSTALL
```bash
pip install tortoise-api
```
### Run your app
- Describe your db models with Tortoise ORM in `models.py` module
```python
from tortoise_api import Model
class User(Model):
id: int = fields.IntField(pk=True)
name: str = fields.CharField(255, unique=True, null=False)
posts: fields.ReverseRelation["Post"]
class Post(Model):
id: int = fields.IntField(pk=True)
text: str = fields.CharField(4095)
user: User = fields.ForeignKeyField('models.User', related_name='posts')
_name = 'text' # `_name` sets the attr for displaying related Post instace inside User (default='name')
```
- Write run script `main.py`: pass your models module in Api app:
```python
from tortoise_api import Api
import models
app = Api().start(models)
```
- Set `DB_URL` env variable in `.env` file
- Run it:
```bash
uvicorn main:app
```
Or you can just fork Completed minimal runnable example from [sample apps](https://github.com/mixartemev/tortoise-api/blob/master/sample_apps/minimal/).
#### And voila:
You have menu with all your models at root app route: http://127.0.0.1:8000
<img width="245" alt="Home - Models list" src="https://github.com/mixartemev/tortoise-api/assets/5181924/0ddaa015-2193-43e1-a6d1-2dbad09bfc7b">
And JSON resources for each db Entity at [/{modelName}]() routes:
<img width="450" alt="User JSON resources" src="https://github.com/mixartemev/tortoise-api/assets/5181924/d4497aa5-1f10-45f3-82e8-f5145b72572e">
And one separate Entity at [/{modelName}/{entity_id}]() routes:
<img width="362" alt="User 1 JSON resource" src="https://github.com/mixartemev/tortoise-api/assets/5181924/f1fed04c-8bf2-462c-ad71-fbee35652b1a">
---
Made with ❤ on top of the Starlette and Tortoise ORM.
Raw data
{
"_id": null,
"home_page": "",
"name": "tortoise-api",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": "",
"keywords": "starlette,fastapi,admin,generator,db-model,crud,tortoise-orm,ASGI-admin",
"author": "",
"author_email": "Artemiev <mixartemev@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/1b/cf/40ca8e078e9a4cbc2e40d3b3d26726ec49a2f04250e6ee253d7e88b89561/tortoise-api-0.4.1.tar.gz",
"platform": null,
"description": "# Tortoise-API\n###### Simplest fastest minimal REST API CRUD generator for Tortoise ORM models.\nFully async Zero config One line ASGI app\n\n#### Requirements\n- Python >= 3.9\n\n### INSTALL\n```bash\npip install tortoise-api\n```\n\n### Run your app\n- Describe your db models with Tortoise ORM in `models.py` module\n```python\nfrom tortoise_api import Model\n\nclass User(Model):\n id: int = fields.IntField(pk=True)\n name: str = fields.CharField(255, unique=True, null=False)\n posts: fields.ReverseRelation[\"Post\"]\n\nclass Post(Model):\n id: int = fields.IntField(pk=True)\n text: str = fields.CharField(4095)\n user: User = fields.ForeignKeyField('models.User', related_name='posts')\n _name = 'text' # `_name` sets the attr for displaying related Post instace inside User (default='name')\n```\n- Write run script `main.py`: pass your models module in Api app:\n```python\nfrom tortoise_api import Api\nimport models\n\napp = Api().start(models)\n```\n- Set `DB_URL` env variable in `.env` file\n- Run it:\n```bash\nuvicorn main:app\n```\nOr you can just fork Completed minimal runnable example from [sample apps](https://github.com/mixartemev/tortoise-api/blob/master/sample_apps/minimal/).\n\n#### And voila:\nYou have menu with all your models at root app route: http://127.0.0.1:8000\n\n<img width=\"245\" alt=\"Home - Models list\" src=\"https://github.com/mixartemev/tortoise-api/assets/5181924/0ddaa015-2193-43e1-a6d1-2dbad09bfc7b\">\n\n\nAnd JSON resources for each db Entity at [/{modelName}]() routes:\n\n<img width=\"450\" alt=\"User JSON resources\" src=\"https://github.com/mixartemev/tortoise-api/assets/5181924/d4497aa5-1f10-45f3-82e8-f5145b72572e\">\n\n\nAnd one separate Entity at [/{modelName}/{entity_id}]() routes:\n\n<img width=\"362\" alt=\"User 1 JSON resource\" src=\"https://github.com/mixartemev/tortoise-api/assets/5181924/f1fed04c-8bf2-462c-ad71-fbee35652b1a\">\n\n\n---\nMade with \u2764 on top of the Starlette and Tortoise ORM.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Simplest fastest minimal REST API CRUD generator for Tortoise ORM models",
"version": "0.4.1",
"project_urls": {
"Homepage": "https://github.com/mixartemev/tortoise-api",
"Repository": "https://github.com/mixartemev/tortoise-api"
},
"split_keywords": [
"starlette",
"fastapi",
"admin",
"generator",
"db-model",
"crud",
"tortoise-orm",
"asgi-admin"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b5eb0620c5a590be8773f4630588761b5f398b3e9ca2d1750dd62b20ad368603",
"md5": "58cdd1931ff71c4c905702480503e8b3",
"sha256": "1ff24b431794b258b20bf83f8f4882ddf41b224f97063b2d1f8b2b72eb616446"
},
"downloads": -1,
"filename": "tortoise_api-0.4.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "58cdd1931ff71c4c905702480503e8b3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 7544,
"upload_time": "2023-09-14T19:16:31",
"upload_time_iso_8601": "2023-09-14T19:16:31.649982Z",
"url": "https://files.pythonhosted.org/packages/b5/eb/0620c5a590be8773f4630588761b5f398b3e9ca2d1750dd62b20ad368603/tortoise_api-0.4.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1bcf40ca8e078e9a4cbc2e40d3b3d26726ec49a2f04250e6ee253d7e88b89561",
"md5": "c8544e11f85e27db1a239c8e9abd2604",
"sha256": "7d55b30c4a1697a2a5a020c1fe5ab2bae3bdf9d5a5c4bc1f4ef1dca72d5be559"
},
"downloads": -1,
"filename": "tortoise-api-0.4.1.tar.gz",
"has_sig": false,
"md5_digest": "c8544e11f85e27db1a239c8e9abd2604",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 7031,
"upload_time": "2023-09-14T19:16:32",
"upload_time_iso_8601": "2023-09-14T19:16:32.968625Z",
"url": "https://files.pythonhosted.org/packages/1b/cf/40ca8e078e9a4cbc2e40d3b3d26726ec49a2f04250e6ee253d7e88b89561/tortoise-api-0.4.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-14 19:16:32",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mixartemev",
"github_project": "tortoise-api",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "tortoise-api"
}