fastapi-pagination
FastAPI pagination
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-paginationuv
uv add fastapi-paginationpoetry
poetry add fastapi-paginationInstalling 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
Tags
More Dynamic Content packages
MarkupSafe provides a text object that escapes…
permissive · top 100 on PyPI
Jinja2Jinja2 is a templating engine that renders…
permissive · top 100 on PyPI
soupsieveSoupsieve is a CSS selector library designed to…
permissive · top 100 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
FlaskFlask is a lightweight WSGI web application…
permissive · top 1,000 on PyPI
MakoMako compiles Python-embedded templates into…
permissive · top 1,000 on PyPI
django-cursor-paginationImplements cursor-based pagination for Django…
permissive · top 15,000 on PyPI
FastAPI-SQLAlchemyProvides middleware and helpers to integrate…
permissive · top 15,000 on PyPI
fastcrudFastCRUD provides async CRUD operations and…
permissive · top 15,000 on PyPI
flask-paginateAdds pagination UI components to Flask…
permissive · top 15,000 on PyPI
fastapi-filterAdds declarative filtering, sorting, and…
permissive · top 15,000 on PyPI
paginateDivides large lists or query results into…
permissive · top 5,000 on PyPI
fastapi-restfulProvides utilities and base classes to reduce…
permissive · top 15,000 on PyPI
fastapi-utilsProvides reusable utilities and base classes…
permissive · top 5,000 on PyPI
fastapi-eventsFastapi-events is an event dispatching and…
permissive · top 15,000 on PyPI
tableau-api-libProvides Python bindings to call Tableau…
permissive · top 5,000 on PyPI