Simplest fastest minimal REST API CRUD generator for Tortoise ORM models
Project description
Tortoise-API
Simplest fastest minimal REST API CRUD generator for Tortoise ORM models.
Fully async Zero config One line ASGI app
Requirements
- Python >= 3.10
INSTALL
pip install tortoise-api
Run your app
- Describe your db models with Tortoise ORM in
models.py
module
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:
from tortoise_api import Api
import models
app = Api().start(models)
- Set
DB_URL
env variable in.env
file - Run it:
uvicorn main:app
Or you can just fork Completed minimal runnable example from sample apps.
And voila:
You have menu with all your models at root app route: http://127.0.0.1:8000
And JSON resources for each db Entity at /{modelName} routes:
And one separate Entity at /{modelName}/{entity_id} routes:
Made with ❤ on top of the Starlette and Tortoise ORM.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tortoise_api-0.10.5.tar.gz
(10.0 kB
view details)
Built Distribution
File details
Details for the file tortoise_api-0.10.5.tar.gz
.
File metadata
- Download URL: tortoise_api-0.10.5.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 333ef1d051f9c31433380648bce1299a0456912e90518edf82a9f7b8d89730a7 |
|
MD5 | c5688a9934f9f182d2816b49802a36ee |
|
BLAKE2b-256 | e82c9d2da106d87e25d040e3d2151ae94526eae3ee2f5add794103cdce75ac2c |
File details
Details for the file tortoise_api-0.10.5-py3-none-any.whl
.
File metadata
- Download URL: tortoise_api-0.10.5-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be28bc7d2f9ab1dd7a99db2157ed39dfde19591ab51465f9e3201a140a22949c |
|
MD5 | 5a797cf5429ee276d92500533111e6db |
|
BLAKE2b-256 | e59b7a036092acd314ad709afb83c3e694870034ce606afc79d15a1d1144a2c9 |