mypy-boto3-shield Type Annotations

1.42.3 · active · verified Sat Apr 11

mypy-boto3-shield provides type annotations for the AWS boto3 Shield service (version 1.42.3), enabling static type checking and improved IDE support. It is automatically generated by the `mypy-boto3-builder` tool, which frequently updates to match new `boto3` releases and features.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to obtain a type-hinted `ShieldClient` and use its methods, benefiting from autocompletion and static type checking. It also shows an example of using a generated `TypedDict` for clearer data structure definitions. The `TYPE_CHECKING` block ensures type imports are only active during type-checking.

import boto3
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from mypy_boto3_shield import ShieldClient
    from mypy_boto3_shield.type_defs import ListAttacksResponseTypeDef

# Instantiate a Shield client with type hints
client: "ShieldClient" = boto3.client("shield")

# Example of using a client method with type checking
try:
    response: "ListAttacksResponseTypeDef" = client.list_attacks()
    print(f"Found {len(response.get('Attacks', []))} Shield attacks.")
except Exception as e:
    print(f"Error listing attacks: {e}")

# Example of a TypedDict for input (if applicable, or output)
def process_response_action(action: "ResponseActionOutputTypeDef") -> None:
    if 'Block' in action:
        print(f"Action is a block: {action['Block']}")
    elif 'Count' in action:
        print(f"Action is a count: {action['Count']}")

# For demonstration, typically this comes from an API call
example_action: "ResponseActionOutputTypeDef" = {"Block": {}}
process_response_action(example_action)

view raw JSON →