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.3.1.tar.gz (2.6 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.3.1-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tortoise_pagination-1.3.1.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.3 Linux/6.14.2-arch1-1

File hashes

Hashes for tortoise_pagination-1.3.1.tar.gz
Algorithm Hash digest
SHA256 0c61331e0733f26f50a6ab0c5744a15ed5c59e818a32f75b4007d81145ad01b3
MD5 1f51ffce5403f60f309f5daddd9b6e45
BLAKE2b-256 04844f7b29337a1bc274b47dcbb30c3f5362eb407f006a4b47e34e2a6e260b66

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tortoise_pagination-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.3 Linux/6.14.2-arch1-1

File hashes

Hashes for tortoise_pagination-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 514efab392c00399d34f12dd306329e539d7c1d9ae054b16da792d3fdc9c0f22
MD5 715c6b2c5162e41bad0d69523b9a9c4b
BLAKE2b-256 f470a02c913383467ee7bdb29e3a6c995c89f59587ce279b35e2aabbacecb7e1

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