Skip to content

Pagination Integration (fastapi_responseschema.integrations.pagination)

Class AbstractPagedResponseSchema

class AbstractPagedResponseSchema(AbstractPage[T], AbstractResponseSchema[T],
                                  Generic[T])

[view_source]

Abstract generic model for building response schema interfaces with pagination logic.

Class PagedSchemaAPIRoute

class PagedSchemaAPIRoute(SchemaAPIRoute)

[view_source]

A SchemaAPIRoute class with pagination support. Must be subclassed setting at least SchemaAPIRoute.response_model.

Usage:

from typing import Generic, TypeVar
from fastapi_responseschema.integrations.pagination import AbstractPagedResponseSchema

T = TypeVar("T")
class MyResponseSchema(AbstractPagedResponseSchema[T], Generic[T]):
    ...

class MyAPIRoute(SchemaPagedAPIRoute):
    response_schema = MyResponseSchema
    paged_response_schema = MyResponseSchema

from fastapi import APIRouter

router = APIRouter(route_class=MyAPIRoute)

Class PaginationMetadata

class PaginationMetadata(BaseModel)

[view_source]

Pagination metadata model for pagination info.

Arguments:

  • total int - Total number of items.
  • page_size int - Number of items per page.
  • page int - Page number.
  • links dict - Object containing pagination links.

from_abstract_page_create

@classmethod
def from_abstract_page_create(cls, total: int,
                              params: SupportedParams) -> "PaginationMetadata"

[view_source]

Create pagination metadata from an abstract page.

Arguments:

  • total int - Total number of items.
  • params SupportedParams - A FastaAPI Pagination Params instance.

Returns:

  • PaginationMetadata - PaginationMetadata instance

Class PaginationParams

class PaginationParams(BaseModel, AbstractParams)

[view_source]

Pagination Querystring parameters

Arguments:

  • page int - The page number.
  • page_size int - Number of items per page.