mypy-boto3-inspector-scan type stubs
mypy-boto3-inspector-scan provides PEP 561 compatible type annotations for the `boto3` AWS SDK's Inspector Scan service. It helps enable static type checking for `boto3` code with tools like MyPy, catching potential errors before runtime. The current version is 1.42.12, generated by `mypy-boto3-builder 8.12.0`. Releases are frequent, typically mirroring `boto3` and AWS service updates.
Warnings
- breaking Python 3.8 support has been removed since `mypy-boto3-builder 8.12.0`. Projects using older Python versions will need to upgrade Python or pin to an older version of `mypy-boto3-*` packages to maintain compatibility.
- breaking TypeDef naming conventions changed in builder version 8.9.0, including shorter names for packed method arguments (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`) and postfix relocation for conflicting names. This may break existing explicit type annotations in your codebase.
- gotcha These packages provide only type stubs, not the runtime implementation of the AWS SDK. `boto3` (or `aioboto3` for async) must be installed alongside `mypy-boto3-*` packages for your code to execute successfully.
- gotcha To ensure accurate type checking and prevent unexpected `mypy` errors, the version of `mypy-boto3-inspector-scan` should ideally be kept synchronized with the version of `boto3` you are using. Significant version drift can lead to outdated or incorrect type hints.
Install
-
pip install mypy-boto3-inspector-scan boto3 -
pip install mypy
Imports
- InspectorScanClient
from mypy_boto3_inspector_scan.client import InspectorScanClient
Quickstart
import boto3
from mypy_boto3_inspector_scan.client import InspectorScanClient
import os
# Instantiate a boto3 client with type hints from mypy-boto3-inspector-scan
# Ensure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
# Using os.environ.get for region to make the example safer without hardcoding
region = os.environ.get('AWS_REGION', 'us-east-1')
try:
# The type annotation 'InspectorScanClient' provides static type checking benefits
client: InspectorScanClient = boto3.client("inspector-scan", region_name=region)
print(f"Successfully created Inspector Scan client in region: {region}")
# Example: List scans (requires appropriate IAM permissions, such as 'inspector-scan:ListScans')
response = client.list_scans()
print("List Scans Response (truncated for brevity):")
print(response.get('scans', [])[:1]) # Print first scan if available
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure 'boto3' is installed and AWS credentials are configured correctly.")
print("Also verify your IAM user/role has permissions for 'inspector-scan:ListScans'.")