mypy-boto3-ses type annotations

1.42.3 · active · verified Thu Apr 09

mypy-boto3-ses provides comprehensive type annotations for the AWS Boto3 SES (Simple Email Service) client, enhancing developer experience with static type checking, auto-completion, and early error detection. It is a generated package from the `mypy-boto3-builder` project, closely tracking `boto3` releases to ensure up-to-date type definitions. The project maintains an active release cadence, often synchronizing with new `boto3` versions and Python updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-ses` to type-hint a Boto3 SES client and its associated request/response type definitions for the `send_email` operation. The `TYPE_CHECKING` block ensures that the `mypy-boto3-ses` dependency is only active during type checking, avoiding runtime overhead.

import boto3
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from mypy_boto3_ses.client import SESClient
    from mypy_boto3_ses.type_defs import SendEmailRequestRequestTypeDef, SendEmailResponseTypeDef

def send_ses_email(
    recipient_email: str, 
    sender_email: str, 
    subject: str, 
    body: str
) -> SendEmailResponseTypeDef:
    # In a real application, you might get region_name or credentials differently
    client: SESClient = boto3.client("ses", region_name="us-east-1")

    email_params: SendEmailRequestRequestTypeDef = {
        "Source": sender_email,
        "Destination": {"ToAddresses": [recipient_email]},
        "Message": {
            "Subject": {"Data": subject},
            "Body": {"Text": {"Data": body}},
        },
    }
    response: SendEmailResponseTypeDef = client.send_email(**email_params)
    print(f"Email sent! Message ID: {response['MessageId']}")
    return response

# Example usage (will not actually send email without AWS credentials and setup)
# You would replace these with actual values
# if __name__ == "__main__":
#     from os import environ
#     send_ses_email(
#         recipient_email=environ.get('SES_RECIPIENT_EMAIL', 'test@example.com'),
#         sender_email=environ.get('SES_SENDER_EMAIL', 'sender@example.com'),
#         subject='Test Subject',
#         body='This is a test email body.'
#     )

view raw JSON →