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.5.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.5-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tortoise_pagination-1.1.5.tar.gz
  • Upload date:
  • Size: 2.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.2-arch2-1

File hashes

Hashes for tortoise_pagination-1.1.5.tar.gz
Algorithm Hash digest
SHA256 ba55e8fbc2df73b9ac8f63cbc6c8c143ddcff5599cb87d5eadf2854d47948d97
MD5 8a0990f6c0799790f6bfae1e205f042b
BLAKE2b-256 aa6ea45c9fa71fcf9ff2317e631fc638785c3cb017bd0dab821b31a422c69159

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for tortoise_pagination-1.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b4c388ea9af35618bd670c13ceba68feb4eb3af3bd819c9d26c36f632c5cbf9d
MD5 4a1a77702286f016a13b339f1897d87e
BLAKE2b-256 c5d01179fe0c69d36aa78bc5dee24d8774cb3313840719d9ce951d715c31f62b

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