skillfed

fastapi-pagination

FastAPI pagination

fastapi-pagination v0.15.16 3.9M downloads/30d#2,445 on PyPI1,677
Permissive license MIT Active released

What it is and what it does

fastapi-pagination is a utility library that integrates pagination into FastAPI applications by providing a Page return type and paginate function to handle subset selection and response formatting. It abstracts away the common logic needed to implement pagination across endpoints, supporting both page-based and cursor-based strategies.

The library works with FastAPI's dependency injection and async/await patterns, and includes integrations for popular database libraries like SQLAlchemy to avoid loading entire result sets into memory. You define your endpoint's return type as Page[YourModel], call paginate on your data or query, and the library handles generating the paginated response with metadata. It requires Python 3.10 or higher and depends on fastapi, pydantic, and typing-extensions.

Use it for:

  • Build REST APIs that return large datasets in manageable chunks without loading all records into memory.
  • Add cursor-based pagination to endpoints querying SQLAlchemy ORM models or other SQL databases.
  • Implement page-based pagination for in-memory lists or NoSQL database queries with automatic response formatting.
  • Generate OpenAPI documentation automatically for paginated endpoints without manual schema definition.
  • Support async database queries with pagination across Tortoise ORM or PyMongo without blocking.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Adds pagination support to FastAPI applications with utilities for defining pagination parameters and returning paginated responses across multiple database frameworks.

Yes. Active maintenance, low install friction, permissive MIT license, and no known vulnerabilities make this a safe choice. The library solves a common FastAPI problem with minimal dependencies and integrates cleanly with popular databases. Install if you need pagination in FastAPI endpoints.

Install

fastapi-pagination on PyPI

pip

pip install fastapi-pagination

uv

uv add fastapi-pagination

poetry

poetry add fastapi-pagination

Installing fastapi-pagination

Before you install

Low friction install with three lightweight runtime dependencies (fastapi, pydantic, typing-extensions). Active maintenance with recent releases; last commit 2026-08-14 and 1677 repository stars indicate ongoing support.

License in practice

MIT license permits commercial and private use with minimal restrictions; you may use, modify, and distribute this package freely provided you include the license notice.

Quickstart

pip install fastapi-pagination

from fastapi import FastAPI
from fastapi_pagination import Page, add_pagination, paginate
from pydantic import BaseModel

app = FastAPI()
add_pagination(app)

class Item(BaseModel):
    name: str

items = [Item(name="a"), Item(name="b")]

@app.get("/items")
async def get_items() -> Page[Item]:
    return paginate(items)

Requires Python 3.10 or higher. When working with databases, use database-specific paginate functions (e.g., from fastapi_pagination.ext.sqlalchemy) to avoid loading all data into memory.

Verify before relying

  • Which specific SQL and NoSQL frameworks are supported beyond SQLAlchemy, Tortoise ORM, and PyMongo mentioned in the description.
  • Performance characteristics and memory overhead when paginating large result sets with the default paginate function.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 3 — fastapi, pydantic, typing-extensions
Maintenance actively maintained — 17 days since the last release
Last repo commit
First released
Downloads 3,932,953/month — #2,445 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: fastapi_pagination-0.15.16-py3-none-any.whl

Operating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14

Tags

fastapi pagination librarypage-based cursor paginationsqlalchemy pagination helperfastapi query paginationdatabase result paginationasync pagination fastapipaginate api responses
fastapi-extensionorm-agnosticasync-ready

More Dynamic Content packages