Skip to content

Add generator function to fetch paginated Qradar API data using Range headers #71

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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