mypy-boto3-detective

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

Demonstrates how to initialize a boto3 Detective client and use the provided type stubs for type-checking API responses. This example assumes `boto3` is installed and AWS credentials are configured (e.g., via environment variables).

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}")

view raw JSON →