Skip to main content

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

Home - Models list

And JSON resources for each db Entity at /{modelName} routes:

User JSON resources

And one separate Entity at /{modelName}/{entity_id} routes:

User 1 JSON resource

Made with ❤ on top of the Starlette and Tortoise ORM.

Project details


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 hashes)

Uploaded Source

Built Distribution

tortoise_api-0.4.1-py3-none-any.whl (7.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page