Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Document an example implementation and usage of BaseHATEOASPaginator #1074

Merged
merged 2 commits into from
Oct 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions singer_sdk/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,37 @@ class BaseHATEOASPaginator(BaseAPIPaginator[Optional[ParseResult]], metaclass=AB

This paginator expects responses to have a key "next" with a value
like "https://api.com/link/to/next-item".

The :attr:`~singer_sdk.pagination.BaseAPIPaginator.current_value` attribute of
this paginator is a `urllib.parse.ParseResult`_ object. This object
contains the following attributes:

- scheme
- netloc
- path
- params
- query
- fragment

That means you can access and parse the query params in your stream like this:

.. code-block:: python

class MyHATEOASPaginator(BaseHATEOASPaginator):
def get_next_url(self, response):
return response.json().get("next")

class MyStream(Stream):
def get_new_paginator(self):
return MyHATEOASPaginator()

def get_url_params(self, next_page_token) -> dict:
if next_page_token:
return dict(parse_qsl(next_page_token.query))
return {}

.. _`urllib.parse.ParseResult`:
https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlparse
"""

def __init__(self, *args: Any, **kwargs: Any) -> None:
Expand Down