<@U04S8PLJWMT> how can I create a stream that need...
# ask-ai
b
@kapa.ai how can I create a stream that needs to make a second request per record to get the actual record data. The request to the paginated api does only contain the ID and partial data
k
To create a stream in Airbyte where you first fetch a list of records (with only IDs and partial data) and then make a second request per record to fetch the full data, you should use the concept of partitioning or subresource streams. ### Approach 1. Fetch the list of IDs (parent resource): - Your first API call should retrieve the list of records, each containing an ID and possibly some partial data. 2. Iterate over IDs to fetch full records (child resource): - For each ID, make a second API call to fetch the complete data for that record. This pattern is common when APIs do not provide all the data in the initial paginated response and require a follow-up request per item. ### How to Implement #### In the Connector Builder UI - Use the Partitioning feature to configure your connector to iterate through all partitions (in this case, the IDs from the first call). - The documentation provides examples, such as fetching responses for each survey in SurveySparrow, where you must first get all survey IDs and then fetch responses for each survey ID. The survey IDs act as partitions for the responses stream. > "Partitioning is required if the records of a stream are grouped into buckets based on an attribute or parent resources that need to be queried separately to extract the records." > "The partitioning feature can be used to configure your connector to iterate through all partitions." > [Partitioning](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/partitioning) #### In Custom Python Connectors - You can implement this by first fetching the list of IDs and then, in your stream logic, iterating over those IDs to make a request for each one. - The Airbyte forum also discusses a similar pattern, where you prefetch IDs and then make a request per ID. You can skip making requests if the list of IDs is empty by checking before making the call. > "I need to prefetch some data and using it after that for iterating all the ids one by one and making request for each of them (there is no API for getting more than one record)." > [How can I skip first call in Python HTTP API Stream](https://discuss.airbyte.io/t/3383) ### Summary - Use partitioning in the Connector Builder UI for this pattern. - In custom code, prefetch IDs and iterate over them to fetch full records. - Ensure you handle the case where the list of IDs is empty to avoid unnecessary requests. If you need a code example or more detailed configuration, please specify whether you are using the Connector Builder UI or writing a custom Python connector.
b
@kapa.ai I'm using python connector. I want each id request to also use the built in rate limit
k
A message from kapa.ai
To ensure that each per-ID request in your Python connector uses the built-in rate limiting, you should leverage the Airbyte CDK's API budget and call rate policy features. This allows you to define rate limits that apply to all HTTP requests made by your stream, including those made in a loop over IDs. ### How to Implement 1. Define an API Budget with a Rate Limit Policy Use the
HttpAPIBudget
and a rate policy (e.g.,
MovingWindowCallRatePolicy
) in your stream's constructor. This will ensure that all requests, including those made per ID, respect the defined rate limit. Example (from the SurveyMonkey tutorial):
Copy code
python    from airbyte_cdk.sources.streams.call_rate import MovingWindowCallRatePolicy, HttpAPIBudget, Rate     class MyStream(HttpStream, ABC):        def __init__(self, **kwargs):            # Define your rate limit, e.g., 120 requests per minute            policies = [                MovingWindowCallRatePolicy(                    rates=[Rate(limit=120, interval=datetime.timedelta(minutes=1))],                    matchers=[],                ),            ]            api_budget = HttpAPIBudget(policies=policies)            super().__init__(api_budget=api_budget, **kwargs)
This setup ensures that every HTTP request made by the stream (including those in a loop over IDs) will be rate-limited according to your policy. You do not need to manually add
sleep()
calls or custom logic for rate limiting—Airbyte will handle it for you. 2. Iterate Over IDs in Your Stream Logic In your
read_records
or similar method, after fetching the list of IDs, loop over them and make a request for each. The rate limiting will be automatically enforced for each request.
Copy code
python    def read_records(self, ...):        ids = self.fetch_ids_somehow()        for id in ids:            response = self._send_request_for_id(id)            yield self.parse_response(response)
### Key Points - The rate limit policy applies to all requests made by the stream, including those in per-ID loops. - No need to manually manage timing or sleep between requests. - This approach is supported in Airbyte CDK Python connectors as of recent versions. For a full example, see the SurveyMonkey connector tutorial, which demonstrates configuring a moving window rate limit policy in a custom Python connector [Concurrent](https://docs.airbyte.com/platform/connector-development/tutorials/custom-python-connector/concurrency). If you need to use a different rate limiting policy (e.g., fixed window), you can adjust the policy type and parameters accordingly. --- References: - [Custom Python Connector: Concurrency and Rate Limiting](https://docs.airbyte.com/platform/connector-development/tutorials/custom-python-connector/concurrency) - [API Budget and Rate Limiting in YAML](https://docs.airbyte.com/platform/connector-development/config-based/understanding-the-yaml-file/rate-limit-api-budget)