mypy-boto3-inspector: AWS Inspector Type Stubs for Boto3

1.42.3 · active · verified Sat Apr 11

mypy-boto3-inspector provides PEP 561 compliant type annotations (stubs) for the AWS Inspector service client in boto3, enabling static type checking with tools like MyPy. It is part of the `mypy-boto3-builder` ecosystem, which generates stubs for all AWS services. The library is actively maintained with frequent updates following boto3 and AWS API changes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the type stubs for the AWS Inspector client with boto3. It shows importing the client type and a specific response TypeDef, then using them to type-hint a boto3 client and its method return values. This allows MyPy to catch potential type mismatches or incorrect attribute access at compile time.

import boto3
from mypy_boto3_inspector.client import InspectorClient
from mypy_boto3_inspector.type_defs import DescribeAssessmentRunsResponseTypeDef
import os

def get_inspector_assessment_runs() -> DescribeAssessmentRunsResponseTypeDef:
    # Ensure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
    # This example requires 'AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'AWS_REGION_NAME'
    # to be set for boto3 to authenticate.
    if not all(os.environ.get(key) for key in ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'AWS_REGION_NAME']):
        print("Warning: AWS credentials not found in environment. Using default session config.")

    client: InspectorClient = boto3.client("inspector")
    print("Attempting to describe AWS Inspector assessment runs...")
    response = client.describe_assessment_runs()
    print(f"Found {len(response['assessmentRuns'])} assessment runs.")
    # MyPy will now correctly type-check 'response' against DescribeAssessmentRunsResponseTypeDef
    # For example, response['assessmentRuns'] is correctly typed as a list of AssessmentRunTypeDef
    return response

if __name__ == "__main__":
    try:
        result = get_inspector_assessment_runs()
        # You can now safely access typed attributes
        if result['assessmentRuns']:
            print(f"First assessment run ARN: {result['assessmentRuns'][0]['arn']}")
    except Exception as e:
        print(f"An error occurred: {e}")

view raw JSON →