Pagination

Async utilities for handling paginated API responses.

class clash_royale.aio.PaginatedList[source]

Bases: Generic[ResourceType]

Async lazy-loading paginated list that fetches pages on demand.

Supports async iteration and explicit async methods for indexed access.

Example usage:

# Async iteration (lazy loading)
async for clan in client.clans.search("royal"):
    print(clan.name)

# Explicit index access
clan = await results.get(5)

# Explicit slice access
clans = await results.slice(0, 10)

# Fetch all results
all_clans = await results.all()
__init__(client: Client, endpoint: str, model: type[ResourceType], params: PaginationParams | ClanSearchParams | None = None)[source]
async get(index: int) ResourceType[source]

Get item at index, fetching pages as needed.

Parameters:

index – The index of the item to retrieve.

Returns:

The item at the specified index.

Raises:
  • IndexError – If index is out of range.

  • ValueError – If index is negative.

async slice(start: int, stop: int) list[ResourceType][source]

Get a slice of items, fetching pages as needed.

Parameters:
  • start – Start index (inclusive).

  • stop – Stop index (exclusive).

Returns:

List of items in the specified range.

async all() list[ResourceType][source]

Fetch and return all items.

Warning

This method fetches all pages from the API, which may result in many requests and large memory usage for endpoints with many results. Consider using limit or async iteration for large datasets.

Returns:

List of all items.

async first() ResourceType | None[source]

Get the first item, or None if empty.

Returns:

The first item or None.