Skip to main content

Effortless pagination for FastAPI + SQLAlchemy

Project description

fastapi-paginate

Effortless pagination for FastAPI + SQLAlchemy


Install

pip install fastapi-paginate

Usage

from fastapi import FastAPI, Depends
from fastapi_paginate import paginate, PaginationParams, Page
from sqlalchemy import select

@app.get("/users", response_model=Page[UserResponse])
async def list_users(
    params: PaginationParams = Depends(),
    db: AsyncSession = Depends(get_db),
):
    query = select(User).order_by(User.created_at.desc())
    return await paginate(db, query, params, schema=UserResponse)

Response:

{
    "items": [...],
    "total": 150,
    "page": 1,
    "size": 20,
    "pages": 8,
    "has_next": true,
    "has_prev": false
}

Features

  • One function call — paginate(db, query, params)
  • Auto-counts total rows
  • has_next / has_prev for frontend navigation
  • Generic Page[T] works with any Pydantic schema
  • Query params auto-extracted via PaginationParams dependency
  • Works with any SQLAlchemy select query

License

MIT

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

fastapi_paginate_pro-0.1.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

fastapi_paginate_pro-0.1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_paginate_pro-0.1.0.tar.gz.

File metadata

  • Download URL: fastapi_paginate_pro-0.1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for fastapi_paginate_pro-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ac87c3aa2d3cc5f156dc8735dc73aacfa05a1a11c182d1367dae10c38245d507
MD5 7465d33f045dca0f70612aaf448de374
BLAKE2b-256 0d779837b834540803f76fb778fb08d60f34c0c0eef44e5a22a15d7753b6bb31

See more details on using hashes here.

File details

Details for the file fastapi_paginate_pro-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_paginate_pro-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 afee0105aecfb823e74f04e11fc82fa550abcc175f248d2b2035e961d78dd8d1
MD5 42f31df98fc816fd4a646a4abe503098
BLAKE2b-256 62925a9c3b0c6600b52d71ba3bb0714a76f0a1ba9c09be13189c5953ef992172

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