Skip to content

Conversation

@Devang142
Copy link

Summary

This PR introduces a new generator function fetch_paginated_data to efficiently retrieve paginated data from Qradar API that supports HTTP Range headers.

The function yields each chunk of data along with response headers, status code and request duration, making it suitable for handling large datasets in a memory-efficient way.

Key Features

  • Supports chunked fetching using the "Content-Range" headers.

  • Automatically stops when all records are fetched (based on total from headers).

  • Yields a dictionary for each request containing:

    • data: list of fetched records
    • status_code: status code of API response
    • headers: response headers
    • error: API error detail
    • duration: time taken(seconds) for the request
  • Includes validation for missing or malformed headers.

Example Usage

from qpylib import qpylib

url = "https://<console_ip>/api/asset_model/assets"

for page in qpylib.fetch_paginated_data(url, chunk_size=100):
    data = page["data"]
    status_code = page["status_code"]
    if status_code == 200:
        print(f"Fetched {len(data)} records in {page['duration_seconds']} seconds")

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants