Type annotations for boto3 SES

1.42.3 · active · verified Sun Apr 12

types-boto3-ses provides comprehensive type annotations for the Amazon Simple Email Service (SES) client within the `boto3` library. This package is part of the `mypy-boto3-builder` project, designed to enhance type checking, autocompletion, and static analysis for `boto3` users with tools like MyPy, Pyright, VSCode, and PyCharm. The current version is 1.42.3, with new releases typically following `boto3` updates and `mypy-boto3-builder` improvements.

Warnings

Install

Imports

Quickstart

This example demonstrates how to initialize an SES client and use type annotations for both the client itself and its method responses. Type checkers will use `types-boto3-ses` to provide accurate suggestions and catch potential errors.

import os
from typing import TYPE_CHECKING

import boto3

# Conditionally import type hints only during type checking
if TYPE_CHECKING:
    from types_boto3_ses.client import SESClient
    from types_boto3_ses.type_defs import IdentityListResponseTypeDef

# Ensure AWS credentials are available for boto3
# For example, by setting AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables
# or configuring the AWS CLI.

def list_ses_identities() -> None:
    # boto3.client returns a dynamically typed client. With types-boto3-ses installed,
    # static analysis tools like mypy will correctly infer types.
    # For explicit type hints, you can annotate the client:
    client: SESClient = boto3.client("ses", region_name=os.environ.get('AWS_REGION', 'us-east-1'))

    try:
        # The response type will be correctly inferred by type checkers
        response: IdentityListResponseTypeDef = client.list_identities(IdentityType='EmailAddress')
        print("Verified SES Identities:")
        for identity in response.get('Identities', []):
            print(f"- {identity}")
    except client.exceptions.ClientError as e:
        print(f"Error listing SES identities: {e}")

if __name__ == "__main__":
    # Set a dummy region if not running in an AWS environment
    if 'AWS_REGION' not in os.environ:
        os.environ['AWS_REGION'] = 'us-east-1'
    list_ses_identities()

view raw JSON →