FastAPI Pagination Utilities
This Python package contains utilities to aid in paginating responses from FastAPI applications.
Use
Install fastapi-pagination-utilities using pip:
pip install fastapi-pagination-utilities
The module can then be used as fastapi_pagination:
from fastapi import FastAPI
from fastapi_pagination import (
CURSOR_QUERY, PAGE_SIZE_QUERY, PaginationDetails, PaginatedResults
)
from pydantic import BaseModel
app = FastAPI()
class Widget(BaseModel):
name: str
@app.get(
'/widgets',
summary="List widgets",
description="List all the widgers which are available."
response_model=PaginatedResults[Widget]
)
def list_widgets(
request: Request,
cursor: Optional[str] = CURSOR_QUERY,
page_size: Optional[int] = PAGE_SIZE_QUERY):
# Get pagination.
pagination = PaginationDetails(cursor, page_size)
# list_widgets() should take a page size and offset and return a list of
# results.
results, has_more = list_widgets(pagination.offset, pagination.page_size)
return PaginatedResults(
next=(
str(request.url.include_query_params(cursor=pagination.next_cursor()))
if has_more else None
),
previous=(
str(request.url.include_query_params(cursor=pagination.previous_cursor()))
if pagination.previous_cursor() else None
),
results=results
)
Developer quickstart
This project contains a dockerized testing environment which wraps tox.
Tests can be run using the ./test.sh command:
# Run all PyTest tests and Flake8 checks
$ ./test.sh
# Run just PyTest
$ ./test.sh -e py3
# Run a single test file within PyTest
$ ./test.sh -e py3 -- tests/test_identifiers.py
# Run a single test file within PyTest with verbose logging
$ ./test.sh -e py3 -- tests/test_identifiers.py -vvv
Metadata
Release files for fastapi-pagination-utilities 0.9.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| fastapi-pagination-utilities-0.9.1.tar.gz | 4.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastapi_pagination_utilities-0.9.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.1 kB
Release files / fastapi-pagination-utilities-0.9.1.tar.gz
| Download URL | fastapi-pagination-utilities-0.9.1.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bc00ded2b05f5e0f6baf71a35b15623514443e4e5d5f9c5d3c8782f2d8c0f46f
|
|
BLAKE2b-256 checksum How to use checksums |
c53fbaefc355fafd85f5ea074e62881faca10146d81dd80fcf7fed718eb17b11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / fastapi_pagination_utilities-0.9.1-py3-none-any.whl
| Download URL | fastapi_pagination_utilities-0.9.1-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
946ef9a70794a2529815fae14e2667ff6d93da3d5944ef0766cdbd1ef82990eb
|
|
BLAKE2b-256 checksum How to use checksums |
d08560ec60c3e1886d7af3147e6210b40361377a5e829205929872d2c9074e8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for fastapi-pagination-utilities 0.9.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.