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.2.4.tar.gz (2.5 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.2.4-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tortoise_pagination-1.2.4.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.10.8-arch1-1

File hashes

Hashes for tortoise_pagination-1.2.4.tar.gz
Algorithm Hash digest
SHA256 bf7ddcd42581388b57f9013ac38b3ef71eb208a4ad91fa23cf0c6c28443ff38a
MD5 3832367a024b051fc25812148ce79632
BLAKE2b-256 331136a56461563cea36ba5d9d658e4ba99731fb6e8b22af30b7c2df8b41af23

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tortoise_pagination-1.2.4-py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.10.8-arch1-1

File hashes

Hashes for tortoise_pagination-1.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1a7e649f0db6afc1399ef98f0c223f8da7793c5ac8a9edf132de0f8a0506827b
MD5 a4a6f4d7c23f49ea6f49ea572112b194
BLAKE2b-256 14d2adda5220783ee55dbdac972868c596c25aeaf152173701818b559ad3d209

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