mypy-boto3-detective
mypy-boto3-detective provides type annotations for the AWS boto3 Detective service, enhancing static analysis for Python applications using mypy. It's part of the `mypy-boto3-builder` project, which generates stubs for all boto3 services. The library receives frequent updates, typically aligning with new boto3 and botocore releases to ensure up-to-date type definitions.
Warnings
- breaking Python 3.8 support has been removed across all `mypy-boto3-*` packages with `mypy-boto3-builder` version 8.12.0. Projects using these stubs must target Python 3.9 or newer.
- gotcha `mypy-boto3-detective` provides only type stubs for static analysis. The actual `boto3` library must be installed separately for your application to run at runtime. Failure to install `boto3` will result in runtime import errors.
- gotcha Mismatched versions between `boto3` and `mypy-boto3-detective` can lead to incorrect or incomplete type checking. It is recommended to keep their versions aligned as closely as possible, especially after significant boto3 updates.
- gotcha Type definition names generated by `mypy-boto3-builder` were shortened in version 8.9.0 (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). If upgrading from older stub versions, existing type annotations might require renaming.
Install
-
pip install mypy-boto3-detective boto3
Imports
- DetectiveClient
from mypy_boto3_detective import DetectiveClient
Quickstart
import os
from typing import TYPE_CHECKING
import boto3
# Ensure boto3 is installed: pip install boto3
if TYPE_CHECKING:
from mypy_boto3_detective import DetectiveClient
from mypy_boto3_detective.type_defs import ListGraphsResponseTypeDef
def get_detective_client() -> DetectiveClient:
# Use environment variables or other boto3 config for credentials
return boto3.client(
"detective",
aws_access_key_id=os.environ.get("AWS_ACCESS_KEY_ID", ""),
aws_secret_access_key=os.environ.get("AWS_SECRET_ACCESS_KEY", ""),
region_name=os.environ.get("AWS_DEFAULT_REGION", "us-east-1")
)
client = get_detective_client()
try:
# Example API call with type annotation for the response
response: ListGraphsResponseTypeDef = client.list_graphs()
print("Successfully listed Detective graphs:")
for graph in response.get("GraphList", []):
print(f" - Graph ARN: {graph['Arn']}")
except Exception as e:
print(f"Error listing Detective graphs: {e}")