mypy-boto3-inspector2 Type Annotations for AWS Inspector2

1.42.49 · active · verified Sat Apr 11

mypy-boto3-inspector2 provides up-to-date type annotations for the AWS Inspector2 service in boto3, enabling static type checking with tools like MyPy. It ensures your boto3 code interacting with Inspector2 is type-safe and helps catch potential errors at development time. The library is part of the mypy-boto3-builder project, which frequently releases new versions to keep pace with boto3 updates and AWS API changes. The current version is 1.42.49.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-inspector2` to add type annotations to your boto3 Inspector2 client. It shows importing the `Inspector2Client` type and a `TypeDef` for filtering, ensuring that your client calls and parameter structures are type-checked by MyPy.

import boto3
from mypy_boto3_inspector2.client import Inspector2Client
from mypy_boto3_inspector2.type_defs import ListFindingsFilterTypeDef

def get_inspector2_findings(region: str) -> None:
    # Initialize a boto3 client with type annotations
    client: Inspector2Client = boto3.client("inspector2", region_name=region)

    # Define a filter using a TypedDict for type safety
    filters: ListFindingsFilterTypeDef = {
        "findingStatus": {"comparison": "EQUALS", "value": "ACTIVE"}
    }

    print(f"Listing active Inspector2 findings in {region}...")
    try:
        response = client.list_findings(filter=filters, maxResults=5)
        for finding in response.get("findings", []):
            print(f"  Finding ARN: {finding.get('findingArn')}, Status: {finding.get('status')}")
        print(f"Total findings listed: {len(response.get('findings', []))}")
    except client.exceptions.ClientError as e:
        print(f"Error listing findings: {e}")

# Example usage (ensure AWS credentials are configured or in environment)
if __name__ == "__main__":
    get_inspector2_findings("us-east-1")

view raw JSON →