Skip to content

Pagination

Stateless cursor-based pagination for queries and scans.

pagination

Pagination support for Dynantic.

This module provides data structures and utilities for external pagination control, enabling FastAPI backends to return pagination cursors to frontends.

PageResult dataclass

Bases: Generic[T]

Represents a single page of results with pagination cursor.

Attributes:

Name Type Description
items list[T]

List of model instances for this page

last_evaluated_key dict[str, Any] | None

Cursor for the next page (None if no more pages)

count int

Number of items in this page

Source code in dynantic/pagination.py
@dataclass
class PageResult(Generic[T]):
    """
    Represents a single page of results with pagination cursor.

    Attributes:
        items: List of model instances for this page
        last_evaluated_key: Cursor for the next page (None if no more pages)
        count: Number of items in this page
    """

    items: list[T]
    last_evaluated_key: dict[str, Any] | None
    count: int

    @property
    def has_more(self) -> bool:
        """Returns True if there are more pages available."""
        return self.last_evaluated_key is not None

has_more property

has_more: bool

Returns True if there are more pages available.