Skip to main content

Pagination for Tortoise-ORM on FastAPI

Project description

Usage

Supposing in myapp.schema you have a pydantic BaseModel to represent your model

from fastapi import Depends
from tortoise_pagination import Pagination, Page

from myapp.main import app
from myapp.models import MyModel
from myapp.schema import MySchema


@app.get('/mymodel')
async def my_view(pagination: Depends(Pagination.from_query)) -> Page[MySchema]:
    return await pagination.paginated_response(MyModel.all(), MySchema)

now you can request with:

curl http://localhost:8000/mymodel?offset=0&limit=20

returned structure:

  • items list[MySchema]
  • count: NonNegativeInt -> the number of entries for this queryset (MyModel.all().count()) wich the frontend will need to be able to display a pagination

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_pagination-1.1.4.tar.gz (2.1 kB view hashes)

Uploaded Source

Built Distribution

tortoise_pagination-1.1.4-py3-none-any.whl (2.6 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