All Projects → mtShaikh → flask-rest-paginate

mtShaikh / flask-rest-paginate

Licence: MIT license
Pagination Extension for flask-restful

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to flask-rest-paginate

Popularmovies
🎥 Movie discovery app showcasing Android best practices with Google's recommended architecture: MVVM + Repository + Offline support + Android Architecture Components + Paging library & Retrofit2.
Stars: ✭ 142 (+688.89%)
Mutual labels:  pagination
Pagerfanta
Pagination library for PHP applications with support for several data providers
Stars: ✭ 175 (+872.22%)
Mutual labels:  pagination
V Selectpage
SelectPage for Vue2, list or table view of pagination, use tags for multiple selection, i18n and server side resources supports
Stars: ✭ 211 (+1072.22%)
Mutual labels:  pagination
Vue Pagination 2
Vue.js 2 pagination component
Stars: ✭ 144 (+700%)
Mutual labels:  pagination
React Paginate
A ReactJS component that creates a pagination
Stars: ✭ 2,169 (+11950%)
Mutual labels:  pagination
Vue Bootstrap4 Table
Advanced table based on Vue 2 and Bootstrap 4 ⚡️
Stars: ✭ 187 (+938.89%)
Mutual labels:  pagination
Bootstrap Table
An extended table to integration with some of the most widely used CSS frameworks. (Supports Bootstrap, Semantic UI, Bulma, Material Design, Foundation, Vue.js)
Stars: ✭ 11,068 (+61388.89%)
Mutual labels:  pagination
Instagram Proxy Api
CORS compliant API to access Instagram's public data
Stars: ✭ 245 (+1261.11%)
Mutual labels:  pagination
Advancedlist
Advanced List View for SwiftUI with pagination & different states
Stars: ✭ 165 (+816.67%)
Mutual labels:  pagination
React Table
⚛️ Hooks for building fast and extendable tables and datagrids for React
Stars: ✭ 15,739 (+87338.89%)
Mutual labels:  pagination
Vuejs Datatable
A Vue.js component for filterable and paginated tables.
Stars: ✭ 148 (+722.22%)
Mutual labels:  pagination
Combine Pagination
A JavaScript library for paginating data from multiple sources 🦑
Stars: ✭ 157 (+772.22%)
Mutual labels:  pagination
Rummage ecto
Search, Sort and Pagination for ecto queries
Stars: ✭ 190 (+955.56%)
Mutual labels:  pagination
Rummage phoenix
Full Phoenix Support for Rummage. It can be used for searching, sorting and paginating collections in phoenix.
Stars: ✭ 144 (+700%)
Mutual labels:  pagination
Sqlhelper
SQL Tools ( Dialect, Pagination, DDL dump, UrlParser, SqlStatementParser, WallFilter, BatchExecutor for Test) based Java. it is easy to integration into any ORM frameworks
Stars: ✭ 242 (+1244.44%)
Mutual labels:  pagination
Gorm Paginator
gorm pagination extension
Stars: ✭ 136 (+655.56%)
Mutual labels:  pagination
Nopaginate
Android pagination library (updated 01.05.2018)
Stars: ✭ 180 (+900%)
Mutual labels:  pagination
Tablefilter
A Javascript library making HTML tables filterable and a bit more :)
Stars: ✭ 248 (+1277.78%)
Mutual labels:  pagination
Gatsby Starter Business
Gatsby Business Website Starter
Stars: ✭ 243 (+1250%)
Mutual labels:  pagination
Jquerydatatablesserverside
Asp.Net Core Server Side for Jquery DataTables Multiple Column Filtering and Sorting with Pagination and Excel Export
Stars: ✭ 191 (+961.11%)
Mutual labels:  pagination

Flask Rest Paginate

A Pagination Extension for Flask RESTful.

Installation

Install the extension using

pip install flask-rest-paginate

Usage

In your app, add the extension as follows

from flask import Flask
from flask_restful import Api
from flask_sqlalchemy import SQLAlchemy
from flask_rest_paginate import Pagination

app = Flask(__name__)

app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///paginate-test.db"
db = SQLAlchemy(app)

pagination = Pagination(app, db)

Use in your project as

pagination.paginate(AuthorModel, author_schema)

You can also pass the sqlalchemy query object as

pagination.paginate(AuthorModel.query.filter_by(id=author_id), author_schema)

If you want to use marshmallow schemas then set the third param True

pagination.paginate(AuthorModel, marshamllow_author_schema, True)

Customize your pagination schema

If you want create a custom pagination schema. You should pass pagination_schema_hook and return a Dict with you custom schema

res = pagination.paginate(
                AuthorModel,
                schema,
                True,
                pagination_schema_hook=lambda current_page, page_obj: {
                    "next": page_obj.has_next,
                    "prev": page_obj.has_prev,
                    "current": current_page,
                    "pages": page_obj.pages,
                    "per_page": page_obj.per_page,
                    "total": page_obj.total,
                },
            )

You can also customize key names where data and pagination info are placed, setting the configuration variables:

app.config['PAGINATE_PAGINATION_OBJECT_KEY'] = "page_info"
app.config['PAGINATE_DATA_OBJECT_KEY'] = "results"

...

{
    "page_info": {
        "currentPage": 1,
        "hasNext": false,
        "hasPrev": false,
        "pages": 1,
        "size": 20,
        "totalElements": 2
    }
    "results": {
        ...
    }
}

Furthermore, pagination info can be moved directly to the root of the result object:

app.config['PAGINATE_PAGINATION_OBJECT_KEY'] = None
app.config['PAGINATE_DATA_OBJECT_KEY'] = "results"

...

{
    "currentPage": 1,
    "hasNext": false,
    "hasPrev": false,
    "pages": 1,
    "size": 20,
    "totalElements": 2
    "results": {
        ...
    }
}

Example:

Check the example folder for an example of the extension.

Contributing

We are always grateful for any kind of contribution including but not limited to bug reports, code enhancements, bug fixes, and even functionality suggestions.

You can report any bug you find or suggest new functionality with a new issue.

If you want to add yourself some functionality to the extension:

  • Open an issue
  • Comment there you are working on a new functionality
  • Fork the repo
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Adds my new feature')
  • Push to the branch (git push origin my-new-feature)
  • Create a new Pull Request
  • mention the issue number in the PR description as fixes #123, #321
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].