mypy-boto3-guardduty Type Annotations

1.42.84 · active · verified Sat Apr 11

Type annotations for the `boto3` GuardDuty service, generated with `mypy-boto3-builder`. It provides comprehensive type hints for clients, paginators, literals, and type definitions, ensuring compatibility with static type checkers like mypy and enhancing IDE experiences in VSCode, PyCharm, and others. The library is actively maintained and frequently updated to synchronize with `boto3` and `mypy-boto3-builder` releases, currently at version 1.42.84.

Warnings

Install

Imports

Quickstart

This example demonstrates how to initialize a `GuardDutyClient` with type annotations and list existing detectors. The `TYPE_CHECKING` block ensures that type imports are only active during static analysis, avoiding runtime dependencies. Explicit client annotation is shown for improved IDE autocomplete and type validation.

import boto3
from typing import TYPE_CHECKING
import os

if TYPE_CHECKING:
    from mypy_boto3_guardduty.client import GuardDutyClient
    from mypy_boto3_guardduty.type_defs import ListDetectorsResponseTypeDef

def get_guardduty_detectors() -> None:
    # Explicit type annotation for the client for better IDE support
    client: GuardDutyClient = boto3.client(
        "guardduty",
        region_name=os.environ.get('AWS_REGION', 'us-east-1'),
        aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY'),
        aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET')
    )

    print("Listing GuardDuty detectors...")
    try:
        response: ListDetectorsResponseTypeDef = client.list_detectors()
        detector_ids = response.get('DetectorIds', [])
        if detector_ids:
            print(f"Found {len(detector_ids)} detectors: {', '.join(detector_ids)}")
        else:
            print("No GuardDuty detectors found.")
    except client.exceptions.ClientError as e:
        print(f"Error listing detectors: {e}")

if __name__ == "__main__":
    get_guardduty_detectors()

view raw JSON →