Ofek Eliahu
07/27/2025, 11:41 AMkapa.ai
07/27/2025, 11:41 AMnext_page_token function is called and appears to work, there are a few things to check based on the Airbyte documentation: 1. Return Value of `next_page_token`: The CDK will continue making requests as long as next_page_token returns a non-None value. If your function returns None or an empty value after the first page, pagination will stop. Make sure that your function returns a valid token (e.g., a dictionary with the next page info) as long as there are more pages to fetch. If there are no more pages, it should return None to stop pagination. [See official docs](https://docs.airbyte.com/platform/next/connector-development/cdk-python/http-streams#pagination) 2. How You Use the Token: The value returned by next_page_token is passed to methods like request_params. Ensure that your request_params method correctly uses the token to request the next page. For example, if your token is a URL or a parameter, it must be properly injected into the next request. Example from docs: python def request_params(self, stream_state, stream_slice=None, next_page_token=None): if next_page_token: # Use the token to set the next page params ... else: # Return initial params ... [See tutorial example](https://docs.airbyte.com/platform/next/connector-development/tutorials/custom-python-connector/reading-multiple-pages) 3. Token Extraction Logic: Double-check your logic for extracting the next page token from the response. If the API does not provide a next page token in the response after the first page, or if your extraction logic is incorrect, pagination will stop. Example: python def next_page_token(self, response): links = response.json().get("links", {}) if "next" in links: return {"next_url": links["next"]} else: return None [See tutorial example](https://docs.airbyte.com/platform/next/connector-development/tutorials/custom-python-connector/reading-multiple-pages) 4. Unit Test Your Pagination: The documentation suggests writing unit tests to ensure your pagination logic works as expected. This can help catch issues where the request for the next page is not being made as intended. If after checking these points the issue persists, please provide the relevant code snippets for next_page_token and request_params so we can help debug further. For more details, refer to the official Airbyte documentation on [pagination in Python CDK connectors](https://docs.airbyte.com/platform/next/connector-development/cdk-python/http-streams#pagination) and the [pagination tutorial](https://docs.airbyte.com/platform/next/connector-development/tutorials/custom-python-connector/reading-multiple-pages).Ofek Eliahu
07/27/2025, 11:44 AMdef read_records(
self,
sync_mode: SyncMode,
cursor_field: Optional[List[str]] = None,
stream_slice: Optional[Mapping[str, Any]] = None,
stream_state: Optional[Mapping[str, Any]] = None,
) -> Iterable[StreamData]:
# A cursor_field indicates this is an incremental stream which offers better checkpointing than RFR enabled via the cursor
if self.cursor_field or not isinstance(self.get_cursor(), ResumableFullRefreshCursor):
yield from self._read_pages(
lambda req, res, state, _slice: self.parse_response(
res, stream_slice=_slice, stream_state=state
),
stream_slice,
stream_state,
)
else:
yield from self._read_single_page(
lambda req, res, state, _slice: self.parse_response(
res, stream_slice=_slice, stream_state=state
),
stream_slice,
stream_state,
)
my stream isn't an incremental stream but it does has pageskapa.ai
07/27/2025, 11:44 AMkapa.ai
07/27/2025, 11:44 AM_read_pages) and reading a single page (_read_single_page) based on whether the stream is incremental or uses a resumable full refresh cursor. From the documentation, for a non-incremental stream (i.e., a full refresh stream), the CDK should still support pagination as long as your next_page_token method is implemented correctly. The CDK's pagination logic relies on the next_page_token function: as long as it returns a non-None value, the CDK will continue to request additional pages. This is the standard behavior for HTTP streams in Airbyte CDK, regardless of whether the stream is incremental or full refresh [Pagination](https://docs.airbyte.com/platform/connector-development/cdk-python/http-streams#pagination). However, your code snippet suggests that if the stream is not incremental and uses a ResumableFullRefreshCursor, it will only read a single page. This is consistent with the design of "resumable full refresh" streams, which are intended for APIs that do not support incremental sync but do support pagination with checkpointing (synthetic cursors). In this mode, the stream is expected to manage its own state and pagination, typically by overriding read_records and handling pagination and state updates manually [Implementing Resumable Full Refresh Streams](https://docs.airbyte.com/platform/connector-development/cdk-python/resumable-full-refresh-stream#implementing-resumable-full-refresh-streams). Key points: - If your stream is a standard full refresh stream (not using resumable full refresh), and you have implemented next_page_token, the CDK should call _read_pages and fetch all pages. - If your stream is using a ResumableFullRefreshCursor, the CDK expects you to handle pagination and state management yourself, typically by overriding read_records as described in the documentation. In this case, _read_single_page is called, and you are responsible for fetching additional pages if needed [Implementing Resumable Full Refresh Streams](https://docs.airbyte.com/platform/connector-development/cdk-python/resumable-full-refresh-stream#implementing-resumable-full-refresh-streams). What you should do: - If you want the CDK to handle pagination automatically, do not use a ResumableFullRefreshCursor unless you specifically need resumable full refresh behavior. - If you do need resumable full refresh, you must override read_records and implement the logic to fetch all pages and update the state accordingly. If you provide more details about your stream class (e.g., whether it inherits from a resumable full refresh base or how you define the cursor), I can give more targeted advice. But based on the documentation, this is the expected behavior for the Airbyte CDK [Resumable Full Refresh Streams](https://docs.airbyte.com/platform/connector-development/cdk-python/resumable-full-refresh-stream). If you need the standard full refresh pagination, ensure your stream does not use a resumable full refresh cursor and that your next_page_token is implemented as described in the [pagination documentation](https://docs.airbyte.com/platform/connector-development/cdk-python/http-streams#pagination).Ofek Eliahu
07/27/2025, 11:48 AMfrom abc import abstractmethod
from typing import Any, Dict, Iterable, List, Mapping, MutableMapping, Optional
from airbyte_cdk.sources.streams.http import HttpStream
from airbyte_cdk import TokenAuthenticator
import requests
from requests.utils import parse_header_links
# GitHub pagination constants
_NEXT_PAGE_TOKEN_KEY = "next_page_url"
_DEFAULT_PAGE_SIZE = 100 # GitHub's default and maximum per_page value
class ApiBaseStream(HttpStream):
"""
Base stream for GitHub API.
This class provides common functionality for all GitHub API streams including
authentication, headers, and base URL configuration.
Reference: https://docs.github.com/en/rest
"""
def __init__(
self,
authenticator: TokenAuthenticator,
check: bool = False,
):
"""
Initialize the GitHub API base stream.
Args:
authenticator: Token authenticator for GitHub API
check: Whether this is being called during connection check
"""
super().__init__(authenticator=authenticator)
self.check = check
@property
def url_base(self) -> str:
"""
GitHub API base URL.
Returns:
str: The base URL for GitHub API v4 (REST API)
"""
return "https://api.github.com/"
@property
def http_method(self) -> str:
"""
HTTP method used for requests.
Returns:
str: Default HTTP method (GET)
"""
return "GET"
def request_headers(
self,
stream_state: Optional[Mapping[str, Any]] = None,
stream_slice: Optional[Mapping[str, Any]] = None,
next_page_token: Optional[Mapping[str, Any]] = None,
) -> MutableMapping[str, Any]:
"""
Add GitHub-specific headers to the request.
Args:
stream_state: The current state of the stream
stream_slice: The current slice of the stream
next_page_token: The token for the next page
Returns:
MutableMapping[str, Any]: Headers dictionary with GitHub-specific headers
"""
headers = dict(
super().request_headers(stream_state, stream_slice, next_page_token)
)
# Add GitHub-specific headers
headers.update(
{
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
}
)
return headers
def next_page_token(self, response: requests.Response) -> Optional[Dict[str, Any]]:
"""
Get the next page token from GitHub's Link header.
GitHub uses Link headers for pagination as documented at:
https://docs.github.com/en/rest/using-the-rest-api/using-pagination-in-the-rest-api
Args:
response: The HTTP response from GitHub API
Returns:
Optional[Dict[str, Any]]: Next page token containing the URL, or None if no more pages
"""
# Don't paginate during connection checks
if self.check:
return None
link_header = response.headers.get("Link")
if not link_header:
return None
# Parse GitHub's Link header to find the next page URL
next_page_url = self._parse_next_page_url(link_header)
return {_NEXT_PAGE_TOKEN_KEY: next_page_url} if next_page_url else None
def _parse_next_page_url(self, link_header: str) -> Optional[str]:
"""
Parse GitHub's Link header to extract the next page URL.
GitHub Link header format:
<https://api.github.com/repos/owner/repo/issues?page=2>; rel="next",
<https://api.github.com/repos/owner/repo/issues?page=10>; rel="last"
Args:
link_header: The Link header value from GitHub response
Returns:
Optional[str]: The next page URL if available, None otherwise
"""
links = parse_header_links(link_header)
next_page_links = (link for link in links if link.get("rel") == "next")
page_link = next(next_page_links, {}).get("url")
return page_link
def request_params(
self,
stream_state: Optional[Mapping[str, Any]],
stream_slice: Optional[Mapping[str, Any]] = None,
next_page_token: Optional[Mapping[str, Any]] = None,
) -> MutableMapping[str, Any]:
"""
Build request parameters for GitHub API calls.
Args:
stream_state: The current state of the stream
stream_slice: The current slice of the stream
next_page_token: The token for the next page
Returns:
MutableMapping[str, Any]: Request parameters
"""
params = {}
# If we have a next page token, use the full URL (no additional params needed)
if next_page_token and _NEXT_PAGE_TOKEN_KEY in next_page_token:
# GitHub pagination URLs contain all necessary parameters
return params
# For initial requests, set page size
# During connection checks, use smaller page size for faster validation
params["per_page"] = 1 if self.check else _DEFAULT_PAGE_SIZE
return params
@abstractmethod
def base_path(
self,
*,
stream_state: Optional[Mapping[str, Any]] = None,
stream_slice: Optional[Mapping[str, Any]] = None,
next_page_token: Optional[Mapping[str, Any]] = None,
) -> str:
"""
The base path for the API endpoint.
"""
raise NotImplementedError("Subclasses must implement base_path() method")
def path(
self,
*,
stream_state: Optional[Mapping[str, Any]] = None,
stream_slice: Optional[Mapping[str, Any]] = None,
next_page_token: Optional[Mapping[str, Any]] = None,
) -> str:
"""
Get the path for the API request.
For paginated requests, GitHub provides full URLs in the Link header.
This method extracts the path from those URLs when available.
Args:
stream_state: The current state of the stream
stream_slice: The current slice of the stream
next_page_token: The token for the next page
Returns:
str: The API endpoint path
"""
if next_page_token and _NEXT_PAGE_TOKEN_KEY in next_page_token:
# Extract path from full GitHub URL
# Example: https://api.github.com/repos/owner/repo/issues?page=2
# Should return: repos/owner/repo/issues?page=2
return next_page_token[_NEXT_PAGE_TOKEN_KEY]
return self.base_path(
stream_state=stream_state,
stream_slice=stream_slice,
next_page_token=next_page_token,
)
def parse_response(
self,
response: requests.Response,
*,
stream_state: Mapping[str, Any],
stream_slice: Optional[Mapping[str, Any]] = None,
next_page_token: Optional[Mapping[str, Any]] = None,
) -> Iterable[Mapping[str, Any]]:
"""
Parse the response from the GitHub API.
Args:
response: The API response
stream_state: The current state of the stream
stream_slice: The current slice of the stream
next_page_token: The token for the next page
Returns:
Iterable[Mapping]: The parsed member records
"""
members: List[Mapping[str, Any]] | Mapping[str, Any] = response.json()
# The response should be an array of member objects
if isinstance(members, list):
return members
return [members]kapa.ai
07/27/2025, 11:48 AMkapa.ai
07/27/2025, 11:49 AMResumableFullRefreshCursor is not something you explicitly use in your stream. Instead, it is part of the Airbyte CDK's internal logic for determining how to handle pagination and state management for different types of streams. From the code snippet you posted from the CDK, the decision to use _read_pages (which handles all pages) or _read_single_page (which only fetches one page) depends on the following condition: python if self.cursor_field or not isinstance(self.get_cursor(), ResumableFullRefreshCursor): yield from self._read_pages(...) else: yield from self._read_single_page(...) - If your stream has a cursor_field (i.e., is incremental), or if self.get_cursor() is not a ResumableFullRefreshCursor, it will read all pages. - If your stream does not have a cursor_field and self.get_cursor() is a ResumableFullRefreshCursor, it will only read a single page. Where does ResumableFullRefreshCursor come from? - The knowledge sources do not provide the exact implementation details of get_cursor() or how/when the CDK assigns a ResumableFullRefreshCursor to a stream. - However, the documentation does state that resumable full refresh streams require special handling and are typically enabled by inheriting from a mixin like CheckpointMixin or StateMixin and implementing state methods. If you do not use these mixins or do not implement resumable full refresh logic, your stream should not be using a ResumableFullRefreshCursor by default ([see here](https://docs.airbyte.com/platform/connector-development/cdk-python/resumable-full-refresh-stream#implementing-resumable-full-refresh-streams)). In your code: - You are inheriting from HttpStream and not using any resumable full refresh mixins or cursor classes. - Therefore, unless something in the parent class or Airbyte's internal logic is assigning a ResumableFullRefreshCursor to your stream, your stream should not be using it. If you are seeing behavior where only a single page is fetched: - Double-check if your stream class or any parent class is being wrapped or modified by Airbyte to use resumable full refresh features. - Ensure you are not setting any configuration or metadata that would cause Airbyte to treat your stream as a resumable full refresh stream. Summary: Based on the documentation, if you are not using resumable full refresh mixins or cursor classes, your stream should not be using a ResumableFullRefreshCursor. If it is, this may be due to Airbyte's internal logic or configuration outside of your stream code. The knowledge sources do not provide enough detail to pinpoint exactly where ResumableFullRefreshCursor is being assigned in your case. If you want standard pagination, your current approach (with next_page_token and no incremental or resumable full refresh logic) is correct according to the documentation ([see here](https://docs.airbyte.com/platform/connector-development/cdk-python/http-streams#pagination)). If the issue persists, it may be necessary to review the broader connector configuration or Airbyte version you are using, as the knowledge sources do not provide further details on this internal assignment.