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

Uploaded Python 3

File details

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

File metadata

  • Download URL: tortoise_pagination-1.2.2.tar.gz
  • Upload date:
  • Size: 2.4 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.2.tar.gz
Algorithm Hash digest
SHA256 7a281d620e9cafc1c2f68c093ef2d4dea328a8234f8ca37f50b04807d501f8e3
MD5 160d225869cdd27aa73812f566dac66b
BLAKE2b-256 f2d4d09cd847e9bbf3d20161dac40bdda68613618806d2d9d74535a25ee0f3b3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tortoise_pagination-1.2.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fca848083a2979e34ce255af1204fec6c06e126cb5c70cb38e35313ba70a86b0
MD5 76768bfa3283e0b36995a01cfd5e31ee
BLAKE2b-256 b6c932b52e16a4fcc7f94d10a225096cbb61d7539a6c9c0194847b1d6c9d0ad8

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