A Python library that simplifies pagination in FastAPI applications with support for multiple strategies and database frameworks.
fastapi-pagination is a Python library that simplifies pagination in FastAPI applications. It provides utility functions and data models to paginate database queries and return structured paginated responses, supporting multiple strategies like cursor-based and page-based pagination. It solves the problem of manually implementing pagination logic, reducing boilerplate code and ensuring consistency across endpoints.
FastAPI developers building RESTful APIs that require paginated responses, especially those using SQLAlchemy, Tortoise ORM, PyMongo, or similar database frameworks.
Developers choose fastapi-pagination for its simplicity, flexibility with multiple pagination strategies, and seamless integration with various database frameworks, all while maintaining async/await compatibility and automatic OpenAPI schema generation.
FastAPI pagination 📖
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Supports cursor-based and page-based pagination, offering flexibility for different API designs like infinite scroll or traditional page navigation, as highlighted in the Key Features.
Works with SQLAlchemy, Tortoise ORM, PyMongo, and other frameworks, reducing boilerplate code for various SQL and NoSQL backends, as stated in the introduction.
Built for modern Python with async/await support, enabling non-blocking pagination in asynchronous FastAPI endpoints, which is explicitly mentioned in the features.
Automatically generates paginated response schemas in OpenAPI documentation, as demonstrated in the Quickstart example with the generated schema image.
Uses simple functions like `paginate` and the `Page` class to add pagination with minimal code changes, as shown in the Quickstart code snippet for both in-memory and database queries.
The default `paginate` function loads all data into memory, which can cause performance issues with large datasets, as explicitly warned in the README's database caution note.
Exclusively designed for FastAPI, making it unsuitable for projects using other web frameworks, which limits its applicability and creates vendor lock-in.
For efficient database pagination, you must use specific extensions like `fastapi_pagination.ext.sqlalchemy`, adding setup complexity and potential learning curve beyond the base library.