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.9
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.4.1.tar.gz
(7.0 kB
view details)
Built Distribution
File details
Details for the file tortoise-api-0.4.1.tar.gz
.
File metadata
- Download URL: tortoise-api-0.4.1.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d55b30c4a1697a2a5a020c1fe5ab2bae3bdf9d5a5c4bc1f4ef1dca72d5be559 |
|
MD5 | c8544e11f85e27db1a239c8e9abd2604 |
|
BLAKE2b-256 | 1bcf40ca8e078e9a4cbc2e40d3b3d26726ec49a2f04250e6ee253d7e88b89561 |
File details
Details for the file tortoise_api-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: tortoise_api-0.4.1-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ff24b431794b258b20bf83f8f4882ddf41b224f97063b2d1f8b2b72eb616446 |
|
MD5 | 58cdd1931ff71c4c905702480503e8b3 |
|
BLAKE2b-256 | b5eb0620c5a590be8773f4630588761b5f398b3e9ca2d1750dd62b20ad368603 |