Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nazmulnnb/fastapi-paginate
Fastapi pagination with meta endpoint links(first, last, next, previous)
https://github.com/nazmulnnb/fastapi-paginate
fastapi fastapi-paginate fastapi-pagination pagination pagination-library python sqlalchemy-paginate
Last synced: 4 months ago
JSON representation
Fastapi pagination with meta endpoint links(first, last, next, previous)
- Host: GitHub
- URL: https://github.com/nazmulnnb/fastapi-paginate
- Owner: nazmulnnb
- License: mit
- Created: 2022-04-12T03:56:23.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-26T02:56:27.000Z (over 2 years ago)
- Last Synced: 2024-09-29T02:22:12.285Z (4 months ago)
- Topics: fastapi, fastapi-paginate, fastapi-pagination, pagination, pagination-library, python, sqlalchemy-paginate
- Language: Python
- Homepage: https://fastapi-paginate.netlify.app
- Size: 740 KB
- Stars: 10
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FastAPI Pagination
[![License](https://img.shields.io/badge/License-MIT-lightgrey)](/LICENSE)
[![codecov](https://github.com/nazmulnnb/fastapi-paginate/workflows/Test/badge.svg)](https://github.com/nazmulnnb/fastapi-paginate/actions)
[![PYPI](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![PYPI](https://img.shields.io/pypi/v/fastapi-paginate)](https://pypi.org/project/fastapi-paginate/)fastapi-paginate is an extended work of fastapi-pagination.
fastapi-paginate returns following extra meta information:
* next: endpoint of the next page.
* previous: endpoint of the previous page.
* first: endpoint of the first page.
* last: endpoint of the last page.All of these meta keeps all the filter parameters passed by the client and returns as it is.
If any of these meta is not available, it will return null.example:
![OpenAPI](docs/img/openapi_example.png)## Installation
```bash
# Basic version
pip install fastapi-paginate# All available integrations
pip install fastapi-paginate[all]
```Available integrations:
* [sqlalchemy](https://github.com/sqlalchemy/sqlalchemy)
* [gino](https://github.com/python-gino/gino)
* [databases](https://github.com/encode/databases)
* [ormar](http://github.com/collerek/ormar)
* [orm](https://github.com/encode/orm)
* [tortoise](https://github.com/tortoise/tortoise-orm)
* [django](https://github.com/django/django)
* [piccolo](https://github.com/piccolo-orm/piccolo)
* [sqlmodel](https://github.com/tiangolo/sqlmodel)
* [motor](https://github.com/mongodb/motor)
* [mongoengine](https://github.com/MongoEngine/mongoengine)## Example
```python
from fastapi import FastAPI
from pydantic import BaseModelfrom fastapi_paginate import Page, add_pagination, paginate
app = FastAPI()
class User(BaseModel):
name: str
surname: strusers = [
User(name='Yurii', surname='Karabas'),
# ...
]@app.get('/users', response_model=Page[User])
async def get_users():
return paginate(users)add_pagination(app)
```## sqlalchemy example
```python
from fastapi import FastAPI, Depends
from pydantic import BaseModelfrom fastapi_paginate import Page, add_pagination
from fastapi_paginate.ext.sqlalchemy import paginatefrom sqlalchemy.orm import Session
app = FastAPI()
class UserModel(Base):
name = Column(String)
surname = Column(String)
age = Column(Integer)class User(BaseModel):
name: str
surname: str
age: int@app.get('/users', response_model=Page[User])
async def get_users(db_session: Session = Depends(get_db_session)):
stmt = db_session.query(UserModel)
# add filters
stmt = stmt.filter(UserModel.age < 30)
# sort
stmt = stmt.order_by(asc(UserModel.age))
return paginate(stmt)add_pagination(app)
```This repo is forked from [fastapi-pagination](https://github.com/uriyyo/fastapi-pagination).
Although original repository is already good enough, but I modified it according to my needs and published thinking it might be helpful for some.