Skip to main content

Simple pagination for pydantic models and SQLAlchemy Query objects

Project description

Introduction

This module will help you paginate results from any database if you use the sqlalchemy object Query. The PageModel pydantic model can be easily integrated with FastAPI and swagger.

Getting Started

Here is a brief example of how to use this code.

from pygination import paginate
from pygination.models import PageModel

query = db.query(models.City)

if country_id is not None:
    query = query.filter(models.City.country_id == country_id)
    
page = paginate(query, offset, limit)

print(page)
# Previous page does not exist. Next page is 2. Total number of pages 4

page_model = PageModel.from_orm(page)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygination-0.0.11.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

pygination-0.0.11-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page