Type Annotations for aiobotocore SES
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
-
ModuleNotFoundError: No module named 'aiobotocore'
cause The `types-aiobotocore-ses` package only provides type hints (stubs) and does not install the actual `aiobotocore` runtime library.fixInstall `aiobotocore` explicitly: `pip install aiobotocore` -
mypy: error: Missing type annotations for ... (e.g., client methods or responses)
cause The type stubs for `aiobotocore` or the specific SES service are not installed or not correctly recognized by your type checker.fixEnsure `types-aiobotocore-ses` is installed: `pip install types-aiobotocore-ses` or `pip install 'types-aiobotocore[ses]'`. -
Argument "Source" to "send_email" of "SESClient" has incompatible type "str"; expected "EmailAddress"; (or similar type mismatch errors)
cause You are providing an argument with a type that does not match the expected `TypedDict` or `Literal` type defined in the stubs.fixConsult the `types-aiobotocore-ses` documentation or your IDE's auto-completion to use the correct `TypedDict` for complex arguments, or ensure `Literal` values are correctly used (e.g., `from types_aiobotocore_ses.type_defs import SendEmailRequestTypeDef`). -
TypeError: 'coroutine' object is not callable (or similar runtime errors related to async functions)
cause You are attempting to call an `async` function (e.g., an `aiobotocore` client method) without awaiting it, or outside of an `async` context.fixEnsure all `aiobotocore` client methods are `await`ed, and that they are called from within an `async def` function, which is then run using `asyncio.run()` or similar methods.
Warnings
- breaking Support for Python 3.8 was removed starting with `mypy-boto3-builder 8.12.0` (which generated `types-aiobotocore-ses 3.4.0`). Projects using Python 3.8 will need to upgrade to Python 3.9 or later.
- gotcha `types-aiobotocore-ses` is a 'stubs only' package. It provides type annotations but does not install `aiobotocore` itself or any other runtime dependencies. Your project must explicitly install `aiobotocore` (e.g., `pip install aiobotocore`) for the code to run.
- gotcha For optimal type checking, the version of `types-aiobotocore-ses` should ideally match or be compatible with your installed `aiobotocore` version. Mismatched versions might lead to incorrect or missing type hints, especially after significant AWS API changes.
- breaking Starting with `mypy-boto3-builder 8.9.0`, TypeDef names for packed method arguments were shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`), and conflicting TypeDef `Extra` postfixes were moved. This affects all generated type stubs, including SES, if you relied on the older, longer names.
- gotcha When using `Pylint` with type annotations imported under `typing.TYPE_CHECKING`, Pylint might report 'undefined variables'.
Install
-
pip install types-aiobotocore-ses -
pip install 'types-aiobotocore[ses]' # Recommended for managing multiple service types
Imports
- SESClient
from types_aiobotocore_ses.client import SESClient
- SendEmailRequestTypeDef
from types_aiobotocore_ses.client import SendEmailRequestTypeDef
from types_aiobotocore_ses.type_defs import SendEmailRequestTypeDef
- BehaviorOnMXFailureType
from types_aiobotocore_ses.literals import BehaviorOnMXFailureType
Quickstart
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))