# X-API
###### Simplest fastest minimal REST API CRUD generator for Tortoise ORM models.
Fully async Zero config One line ASGI app
#### Requirements
- Python >= 3.12
### INSTALL
```bash
pip install tortoise-api
```
### Run your app
- Describe your db models with Tortoise ORM in `models.py` module
```python
from x_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 x_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/XyncNet/x-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/XyncNet/x-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/XyncNet/x-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/XyncNet/x-api/assets/5181924/f1fed04c-8bf2-462c-ad71-fbee35652b1a">
---
Made with ❤ on top of the [FastAPI](https://github.com/fastapi/fastapi) and [TortoiseORM](https://tortoise.github.io/).
Raw data
{
"_id": null,
"home_page": null,
"name": "xn-api",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": null,
"keywords": "starlette, fastapi, admin, generator, db-model, crud, tortoise-orm, ASGI-admin",
"author": null,
"author_email": "Artemiev <mixartemev@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/92/fd/51832ca70b68ccbbb07bc0d6fd3947469698216092267831f6ce9cc13776/xn_api-1.0.4.tar.gz",
"platform": null,
"description": "# X-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.12\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 x_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 x_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/XyncNet/x-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/XyncNet/x-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/XyncNet/x-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/XyncNet/x-api/assets/5181924/f1fed04c-8bf2-462c-ad71-fbee35652b1a\">\n\n\n---\nMade with \u2764 on top of the [FastAPI](https://github.com/fastapi/fastapi) and [TortoiseORM](https://tortoise.github.io/).\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Simplest fastest minimal REST API CRUD generator for Tortoise ORM models",
"version": "1.0.4",
"project_urls": {
"Homepage": "https://github.com/XyncNet/x-api",
"Repository": "https://github.com/XyncNet/x-api"
},
"split_keywords": [
"starlette",
" fastapi",
" admin",
" generator",
" db-model",
" crud",
" tortoise-orm",
" asgi-admin"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "796b43ba80db2ac1d85bfb2e74f0409161a23d1e16001c607ef92c14da611dd3",
"md5": "0dbd8cab29f143f297ab88b4e0c5609c",
"sha256": "0f05ef8acebb037aa3b68750bb3c00c8c7c72918bba2bcd026f00dcfe3a0ce0b"
},
"downloads": -1,
"filename": "xn_api-1.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0dbd8cab29f143f297ab88b4e0c5609c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12",
"size": 5759,
"upload_time": "2024-10-31T20:45:49",
"upload_time_iso_8601": "2024-10-31T20:45:49.418745Z",
"url": "https://files.pythonhosted.org/packages/79/6b/43ba80db2ac1d85bfb2e74f0409161a23d1e16001c607ef92c14da611dd3/xn_api-1.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "92fd51832ca70b68ccbbb07bc0d6fd3947469698216092267831f6ce9cc13776",
"md5": "509cd557700261570b4467cd9d38fcac",
"sha256": "660ae544eac12ba679ea999aa4b0d09d68796e8565a98ce24518026f7aed421e"
},
"downloads": -1,
"filename": "xn_api-1.0.4.tar.gz",
"has_sig": false,
"md5_digest": "509cd557700261570b4467cd9d38fcac",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 9047,
"upload_time": "2024-10-31T20:45:51",
"upload_time_iso_8601": "2024-10-31T20:45:51.135142Z",
"url": "https://files.pythonhosted.org/packages/92/fd/51832ca70b68ccbbb07bc0d6fd3947469698216092267831f6ce9cc13776/xn_api-1.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-31 20:45:51",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "XyncNet",
"github_project": "x-api",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "xn-api"
}