Skip to content

pagination

frequenz.client.common.pagination ¤

Module to define the pagination used with the common client.

Classes¤

frequenz.client.common.pagination.Info dataclass ¤

Information about the pagination of a list request.

Source code in frequenz/client/common/pagination/__init__.py
@dataclass(frozen=True, kw_only=True)
class Info:
    """Information about the pagination of a list request."""

    total_items: int
    """The total number of items that match the request."""

    next_page_token: str | None = None
    """The token identifying the next page of results."""

    @classmethod
    def from_proto(cls, pagination_info: PaginationInfo) -> Self:
        """Convert a protobuf PBPaginationInfo to Info object.

        Args:
            pagination_info: Info to convert.
        Returns:
            Info object corresponding to the protobuf message.
        """
        return cls(
            total_items=pagination_info.total_items,
            next_page_token=pagination_info.next_page_token,
        )

    def to_proto(self) -> PaginationInfo:
        """Convert a Info object to protobuf PBPaginationInfo.

        Returns:
            Protobuf message corresponding to the Info object.
        """
        return PaginationInfo(
            total_items=self.total_items,
            next_page_token=self.next_page_token,
        )
Attributes¤
next_page_token class-attribute instance-attribute ¤
next_page_token: str | None = None

The token identifying the next page of results.

total_items instance-attribute ¤
total_items: int

The total number of items that match the request.

Functions¤
from_proto classmethod ¤
from_proto(pagination_info: PaginationInfo) -> Self

Convert a protobuf PBPaginationInfo to Info object.

PARAMETER DESCRIPTION
pagination_info

Info to convert.

TYPE: PaginationInfo

Returns: Info object corresponding to the protobuf message.

Source code in frequenz/client/common/pagination/__init__.py
@classmethod
def from_proto(cls, pagination_info: PaginationInfo) -> Self:
    """Convert a protobuf PBPaginationInfo to Info object.

    Args:
        pagination_info: Info to convert.
    Returns:
        Info object corresponding to the protobuf message.
    """
    return cls(
        total_items=pagination_info.total_items,
        next_page_token=pagination_info.next_page_token,
    )
to_proto ¤
to_proto() -> PaginationInfo

Convert a Info object to protobuf PBPaginationInfo.

RETURNS DESCRIPTION
PaginationInfo

Protobuf message corresponding to the Info object.

Source code in frequenz/client/common/pagination/__init__.py
def to_proto(self) -> PaginationInfo:
    """Convert a Info object to protobuf PBPaginationInfo.

    Returns:
        Protobuf message corresponding to the Info object.
    """
    return PaginationInfo(
        total_items=self.total_items,
        next_page_token=self.next_page_token,
    )

frequenz.client.common.pagination.Params dataclass ¤

Parameters for paginating list requests.

Source code in frequenz/client/common/pagination/__init__.py
@dataclass(frozen=True, kw_only=True)
class Params:
    """Parameters for paginating list requests."""

    page_size: int
    """The maximum number of results to be returned per request."""

    page_token: str
    """The token identifying a specific page of the list results."""

    @classmethod
    def from_proto(cls, pagination_params: PaginationParams) -> Self:
        """Convert a protobuf Params to PaginationParams object.

        Args:
            pagination_params: Params to convert.
        Returns:
            Params object corresponding to the protobuf message.
        """
        return cls(
            page_size=pagination_params.page_size,
            page_token=pagination_params.page_token,
        )

    def to_proto(self) -> PaginationParams:
        """Convert a Params object to protobuf PaginationParams.

        Returns:
            Protobuf message corresponding to the Params object.
        """
        return PaginationParams(
            page_size=self.page_size,
            page_token=self.page_token,
        )
Attributes¤
page_size instance-attribute ¤
page_size: int

The maximum number of results to be returned per request.

page_token instance-attribute ¤
page_token: str

The token identifying a specific page of the list results.

Functions¤
from_proto classmethod ¤
from_proto(pagination_params: PaginationParams) -> Self

Convert a protobuf Params to PaginationParams object.

PARAMETER DESCRIPTION
pagination_params

Params to convert.

TYPE: PaginationParams

Returns: Params object corresponding to the protobuf message.

Source code in frequenz/client/common/pagination/__init__.py
@classmethod
def from_proto(cls, pagination_params: PaginationParams) -> Self:
    """Convert a protobuf Params to PaginationParams object.

    Args:
        pagination_params: Params to convert.
    Returns:
        Params object corresponding to the protobuf message.
    """
    return cls(
        page_size=pagination_params.page_size,
        page_token=pagination_params.page_token,
    )
to_proto ¤
to_proto() -> PaginationParams

Convert a Params object to protobuf PaginationParams.

RETURNS DESCRIPTION
PaginationParams

Protobuf message corresponding to the Params object.

Source code in frequenz/client/common/pagination/__init__.py
def to_proto(self) -> PaginationParams:
    """Convert a Params object to protobuf PaginationParams.

    Returns:
        Protobuf message corresponding to the Params object.
    """
    return PaginationParams(
        page_size=self.page_size,
        page_token=self.page_token,
    )