mypy-boto3-inspector: AWS Inspector Type Stubs for Boto3
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
- breaking Support for Python 3.8 was removed in version 8.12.0 of the `mypy-boto3-builder` ecosystem, affecting all generated stub packages.
- breaking TypeDef naming conventions changed in version 8.9.0, specifically for packed method arguments (shorter names) and conflicting `Extra` postfixes (moved to end). This can break existing type hints.
- gotcha `mypy-boto3-inspector` provides *type stubs only*. You must install `boto3` separately for your code to execute against the actual AWS API.
- gotcha AWS service names can sometimes change or be deprecated within the `mypy-boto3` ecosystem (e.g., `sms-voice` became `pinpoint-sms-voice`). While `inspector` is stable, always check release notes for your specific service if imports or package names stop working.
Install
-
pip install mypy-boto3-inspector -
pip install boto3 mypy
Imports
- InspectorClient
from mypy_boto3_inspector.client import InspectorClient
- DescribeAssessmentRunsResponseTypeDef
from mypy_boto3_inspector.type_defs import DescribeAssessmentRunsResponseTypeDef
Quickstart
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}")