> ## Documentation Index
> Fetch the complete documentation index at: https://docs.validio.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Number of Incidents by Severity

> Summarize incident counts by severity over the past week by paging through a source's incident groups.

## Overview

Get a summary of the severities of a source's incidents without iterating over the incidents themselves. Fetch all incident groups for the last week, page by page, and add up the number of incidents for each severity over the week.

## Steps

**1. Construct the query**

Write the query to fetch incident groups with their severity statistics. Also initialize variables to keep track of the page, the cursor, the time range, and the severity counts.

**2. Iterate over the pages**

Start a loop that continues as long as there are more pages. Execute the query for each page, with a limit of 1000 elements per page.

**3. Add the severity count**

Initialize the counts from the first incident group, then add the counts from every later group.

**4. Print the result**

Once all pages are processed, you have the total count for each severity across the full time range. Print each severity and its number of incidents.

## Full code sample

```python title="Python" theme={null}
import os
from datetime import datetime, timedelta

from validio_sdk.client import Client


async def example(
    source_id: str = os.environ["EXAMPLE_SOURCE_ID"],
):
    client = Client()
    query = """
    query GetIncidents(
      $filter: IncidentGroupsFilter,
      $pagination: PaginationInput
    ) {
      incidentGroups(filter: $filter, pagination: $pagination) {
        elements {
          severityStats {
            highCount
            lowCount
            mediumCount
            totalCount
          }
        }
        pageInfo {
          endCursor
          hasNextPage
        }
      }
    }
    """

    has_next_page = True
    end_cursor = None
    start = datetime.now() - timedelta(days=7)
    end = datetime.now()
    severities = {}

    while has_next_page:
        result = (
            await client.execute(
                query,
                variable_values={
                    "filter": {
                        "source": {
                            "values": [source_id],
                        },
                        "range": {
                            "start": start.isoformat(),
                            "end": end.isoformat(),
                        },
                    },
                    "pagination": {
                        "after": end_cursor,
                        "limit": 1000,
                    },
                },
            )
        )["incidentGroups"]

        for element in result["elements"]:
            if not severities:
                severities = element["severityStats"]
                continue

            for severity, count in element["severityStats"].items():
                severities[severity] += count

        has_next_page = result["pageInfo"]["hasNextPage"]
        end_cursor = result["pageInfo"]["endCursor"]

    for severity, count in severities.items():
        print(f"{severity}: {count}")
```
