Type Annotations for aiobotocore SES

3.4.0 · active · verified Thu Apr 16

The `types-aiobotocore-ses` library provides static type annotations for `aiobotocore`'s SES (Simple Email Service) client. Currently at version 3.4.0, it is generated by `mypy-boto3-builder 8.12.0` and enhances development with `mypy`, `pyright`, and IDE auto-completion for asynchronous AWS operations. It is part of a larger project offering type stubs for various `aiobotocore` services, with releases generally aligned with `aiobotocore` versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize an `aiobotocore` SES client and use it to send an email, leveraging the `types-aiobotocore-ses` annotations for enhanced type checking and IDE auto-completion. The `TYPE_CHECKING` block ensures type imports are only active during static analysis.

import asyncio
from typing import TYPE_CHECKING

from aiobotocore.session import get_session

# These imports are only for type checking and won't be bundled at runtime
if TYPE_CHECKING:
    from types_aiobotocore_ses.client import SESClient
    from types_aiobotocore_ses.type_defs import SendEmailResponseTypeDef

async def send_test_email(recipient: str, sender: str, subject: str, body: str):
    session = get_session()
    async with session.create_client("ses", region_name="us-east-1") as client:
        # Explicit type annotation for the client enables full IDE support and static analysis
        client: "SESClient"

        try:
            response: "SendEmailResponseTypeDef" = await client.send_email(
                Source=sender,
                Destination={
                    "ToAddresses": [recipient]
                },
                Message={
                    "Subject": {"Data": subject},
                    "Body": {"Text": {"Data": body}}
                }
            )
            print(f"Email sent! Message ID: {response.get('MessageId')}")
            return response
        except Exception as e:
            print(f"Error sending email: {e}")
            raise

if __name__ == "__main__":
    # Replace with actual email addresses and content
    recipient_email = "test@example.com"
    sender_email = "noreply@example.com"
    email_subject = "Hello from aiobotocore SES!"
    email_body = "This is a test email sent using aiobotocore with type hints."

    # Make sure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
    # For this example, we'll use os.environ.get for placeholders if actual credentials aren't set.
    # In a real application, you'd configure aiobotocore session for credentials.
    # Example: os.environ.get('AWS_ACCESS_KEY_ID', 'YOUR_ACCESS_KEY')
    #          os.environ.get('AWS_SECRET_ACCESS_KEY', 'YOUR_SECRET_KEY')
    #          os.environ.get('AWS_REGION', 'us-east-1')

    asyncio.run(send_test_email(recipient_email, sender_email, email_subject, email_body))

view raw JSON →