Skip to content

Make an utility that returns an iterator for objects in paginated responses. #7

Description

@EnriqueSoria

In some API clients I found myself doing these things:

class WegowClient(RequestsClient):
    def event_feed(self, page: int | None = None) -> EventFeedResponse:
        return self._perform_request(EventFeedEndpoint(page))

    def get_events(self) -> Iterable[Event]:
        """Returns an iterator containing all concerts"""
        next_page = None
        while True:
            response = self.event_feed(page=next_page)
            yield from response.events
            next_page = response.next_page
            if next_page is None:
                break

It would be nice to have a way to define in an Endpoint how its pagination works so we can easilly return yield all objects from a paginated endpoint.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions