Type annotations for aiobotocore SNS
types-aiobotocore-sns provides static type annotations and code completion for `aiobotocore`'s Amazon SNS service client. It ensures type safety and enhances developer experience by integrating with type checkers like MyPy. The current version is 3.4.0, generated by `mypy-boto3-builder` 8.12.0, and new versions are released regularly in sync with `aiobotocore` and `botocore` updates.
Warnings
- breaking Support for Python 3.8 has been removed in `mypy-boto3-builder` version 8.12.0 and later, which is used to generate `types-aiobotocore-sns` 3.4.0 and subsequent versions. Projects requiring Python 3.8 must use an older version of `types-aiobotocore-sns`.
- breaking In `mypy-boto3-builder` 8.9.0, some `TypeDef` names were shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). If your code explicitly imported these renamed `TypeDefs`, it will break.
- deprecated The `sms-voice` service was deprecated and removed from `mypy-boto3-builder` (version 8.11.0 onwards). Users should switch to `pinpoint-sms-voice` instead.
- gotcha When using PyCharm, performance issues may occur due to how it handles `Literal` overloads. This can lead to slow performance and high CPU usage.
- gotcha For production deployments, `types-aiobotocore-sns` should typically be a development-only dependency. To avoid runtime dependencies, guard type imports with `typing.TYPE_CHECKING`.
Install
-
pip install types-aiobotocore-sns -
pip install 'types-aiobotocore[sns]'
Imports
- SNSClient
from types_aiobotocore_sns.client import SNSClient
- PublishInputTypeDef
from types_aiobotocore_sns.type_defs import PublishInputTypeDef
- TopicArnType
from types_aiobotocore_sns.literals import TopicArnType
Quickstart
import asyncio
from typing import TYPE_CHECKING
from aiobotocore.session import get_session
import os
if TYPE_CHECKING:
from types_aiobotocore_sns.client import SNSClient
async def publish_message():
session = get_session()
# Ensure AWS credentials/config are available via environment variables or config files
# e.g., AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION
async with session.create_client("sns") as client:
client: "SNSClient" # Explicit type annotation for IDEs/MyPy
topic_arn = os.environ.get('AWS_SNS_TOPIC_ARN', 'arn:aws:sns:REGION:ACCOUNT_ID:MyTopic')
message = "Hello from types-aiobotocore-sns!"
try:
response = await client.publish(TopicArn=topic_arn, Message=message)
print(f"Message published: {response['MessageId']}")
except client.exceptions.TopicNotFoundException:
print(f"Error: Topic {topic_arn} not found.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
# You would typically set AWS_SNS_TOPIC_ARN, AWS_REGION, etc., as environment variables.
# For this example, ensure they are set or default values are valid.
asyncio.run(publish_message())