Mypy Boto3 SESV2
mypy-boto3-sesv2 provides comprehensive type annotations for the AWS boto3 SESV2 (Simple Email Service v2) client, paginators, and waiters. It allows developers to leverage static type checking with Mypy for their boto3 code, improving code quality and catching potential errors early. The library is updated frequently, often alongside new boto3/botocore releases and builder improvements, ensuring up-to-date and accurate type definitions. Current version: 1.42.63.
Warnings
- breaking Python 3.8 support was removed and packages migrated to PEP 561. If you are on Python 3.8, you must pin to a version older than 8.12.0.
- breaking TypeDef naming conventions changed in version 8.9.0 (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`). Code that directly imports or references specific generated type definition names may break.
- gotcha The `mypy` tool must be configured to find the stubs. Ensure `mypy-boto3-sesv2` is installed in the same environment where `mypy` is run, or that your `mypy` configuration (e.g., `mypy.ini`) correctly includes the stub paths.
- gotcha AWS services can be renamed or deprecated (e.g., 'sms-voice' to 'pinpoint-sms-voice' in 8.11.0). If you encounter `ModuleNotFoundError` for a service stub, check the official `mypy-boto3-builder` repository for service name changes or deprecations.
- gotcha Mismatching `boto3` runtime versions and `mypy-boto3-*` stub versions can lead to incorrect type checking or runtime errors. For optimal accuracy, keep your `boto3` and `mypy-boto3-sesv2` versions as aligned as possible.
Install
-
pip install mypy-boto3-sesv2 boto3 -
pip install 'mypy-boto3-sesv2[essential]' boto3
Imports
- SESV2Client
from mypy_boto3_sesv2.client import SESV2Client
- SendEmailRequestRequestTypeDef
from mypy_boto3_sesv2.type_defs import SendEmailRequestRequestTypeDef
- Paginator
from mypy_boto3_sesv2.paginator import ListConfigurationSetsPaginator
Quickstart
import boto3
from mypy_boto3_sesv2.client import SESV2Client
from mypy_boto3_sesv2.type_defs import SendEmailRequestRequestTypeDef
import os
# Initialize a boto3 client with type hints
client: SESV2Client = boto3.client(
"sesv2",
region_name=os.environ.get('AWS_REGION', 'us-east-1')
)
# Example: Sending a simple email with type-checked arguments
request_params: SendEmailRequestRequestTypeDef = {
"FromEmailAddress": "sender@example.com", # Replace with a verified sender
"Destination": {
"ToAddresses": [
"recipient@example.com" # Replace with a recipient
]
},
"Content": {
"Simple": {
"Subject": {"Data": "Hello from mypy-boto3-sesv2!"},
"Body": {"Text": {"Data": "This is a test email sent with SESv2."}}
}
}
}
try:
response = client.send_email(**request_params)
print(f"Email sent successfully! Message ID: {response['MessageId']}")
except Exception as e:
print(f"Error sending email: {e}")
# Example: Listing configuration sets using a paginator
paginator = client.get_paginator("list_configuration_sets")
for page in paginator.paginate():
for config_set in page.get("ConfigurationSets", []):
print(f"Configuration Set: {config_set['ConfigurationSetName']}")