mypy-boto3-ses type annotations
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
- breaking Starting with `mypy-boto3-builder` version 8.12.0, Python 3.8 is no longer supported for any generated packages, including `mypy-boto3-ses`. Ensure your project uses Python 3.9 or higher.
- breaking In `mypy-boto3-builder` version 8.9.0, there were breaking changes to TypeDef naming conventions. Packed method arguments now use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`), and conflicting `Extra` postfixes were moved (e.g., `CreateDistributionExtraRequestTypeDef` -> `CreateDistributionRequestExtraTypeDef`). If you relied on specific, longer TypeDef names, they may have changed.
- gotcha While `mypy-boto3-ses` provides type annotations, it is crucial to also install the `boto3` library itself. `mypy-boto3-ses` only adds static typing capabilities and does not include the runtime `boto3` functionality.
- gotcha The `mypy-boto3` ecosystem moved to PEP 561 compliant packages in version 8.12.0 of the builder. This generally means type checkers should discover stubs automatically. However, some IDEs or linters (like older Pylint versions) might require explicit type annotations (as shown in the Quickstart) or `TYPE_CHECKING` guards to avoid 'undefined variable' complaints.
Install
-
pip install mypy-boto3-ses boto3
Imports
- SESClient
from mypy_boto3_ses.client import SESClient
- SendEmailRequestRequestTypeDef
from mypy_boto3_ses.type_defs import SendEmailRequestRequestTypeDef
- SendEmailResponseTypeDef
from mypy_boto3_ses.type_defs import SendEmailResponseTypeDef
Quickstart
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.'
# )