mypy-boto3-inspector2 Type Annotations for AWS Inspector2
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
- breaking Python 3.8 support has been removed for `mypy-boto3-builder` generated packages as of version 8.12.0. Users on Python 3.8 must upgrade to Python 3.9 or newer to receive updates.
- breaking TypeDefs for method arguments or conflicting names might have been renamed in `mypy-boto3-builder` version 8.9.0 to use shorter names or move 'Extra' suffixes. For example, `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`.
- gotcha The `mypy-boto3` ecosystem migrated to PEP 561 compliant packages with `mypy-boto3-builder` version 8.12.0. While `mypy` itself should handle this seamlessly, some other type checkers or tooling might have expected older stub distribution formats.
- gotcha This library provides *only* type annotations. You must install `boto3` separately to get the actual AWS SDK functionality.
- gotcha Service names can change over time within the AWS ecosystem (e.g., `sms-voice` became `pinpoint-sms-voice`). While `inspector2` is stable, be aware that other `mypy-boto3` service packages might require updates if the underlying AWS service name changes.
Install
-
pip install boto3 mypy-boto3-inspector2
Imports
- Inspector2Client
from mypy_boto3_inspector2.client import Inspector2Client
- ListFindingsFilterTypeDef
from mypy_boto3_inspector2.type_defs import ListFindingsFilterTypeDef
Quickstart
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")