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.2.3.tar.gz
(5.1 kB
view details)
Built Distribution
File details
Details for the file tortoise-api-0.2.3.tar.gz
.
File metadata
- Download URL: tortoise-api-0.2.3.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a3d3d1a3428dc2de8bb43df648ace3532f925f5edd37dc91717e4ef97d7ab3d |
|
MD5 | e44ad435362ef6b7cf71a253feb563c2 |
|
BLAKE2b-256 | dc245befc3a1dd70b39ba8c2076755365740b226b9b8db7eb07e93093dd7582c |
File details
Details for the file tortoise_api-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: tortoise_api-0.2.3-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1791517a4cede59e7c906b8721bb36b0ad823e63b2d41cf8d57f909b93784add |
|
MD5 | 2a3917cd72b1bf2226363833d0b0f027 |
|
BLAKE2b-256 | 68742f3b1006fdab755494a794f5774a9eb48952114d83b8b69d28c07c8f15d6 |