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.3.tar.gz (2.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tortoise_pagination-1.1.3-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

Details for the file tortoise_pagination-1.1.3.tar.gz.

File metadata

  • Download URL: tortoise_pagination-1.1.3.tar.gz
  • Upload date:
  • Size: 2.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/6.5.9-arch2-1

File hashes

Hashes for tortoise_pagination-1.1.3.tar.gz
Algorithm Hash digest
SHA256 d5366f672d2ec3c8f87c7f7ce4e5d672d1c0c28f2056ee50ade58c8309b844ef
MD5 d8ea4c99e4a0af794034cdee2f302692
BLAKE2b-256 15fd556face33c5452902b8a2ae95492883c910454b2e6baa52ebd1f21f1d14f

See more details on using hashes here.

File details

Details for the file tortoise_pagination-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: tortoise_pagination-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 2.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/6.5.9-arch2-1

File hashes

Hashes for tortoise_pagination-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d062a1a1ddea82cf1f7963b5a82992fe524963cbdd4db48880e92c3e5e85fd81
MD5 9826939bd9891c1cae2fcd00765b6df6
BLAKE2b-256 eadbe3d88f2f94158f7e552d731f0e47edd93b2f20e8b28a23283ac0a5e9284a

See more details on using hashes here.

Supported by

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