Mypy Boto3 SNS Type Stubs

1.42.3 · active · verified Thu Apr 09

mypy-boto3-sns provides type annotations for the AWS Boto3 SNS (Simple Notification Service) client and resources. It enhances development experience with type checking tools like mypy, pyright, and IDEs (VSCode, PyCharm) by offering static analysis for Boto3 code. This package, currently at version 1.42.3, is generated by `mypy-boto3-builder` (version 8.12.0) and typically releases in sync with `boto3` updates.

Warnings

Install

Imports

Quickstart

This example demonstrates how to obtain an SNS client with and without explicit type annotations using `mypy-boto3-sns`. Type annotations are primarily for static analysis tools during development, not for runtime execution. The `TYPE_CHECKING` block shows how `mypy` would verify types.

import boto3
from typing import TYPE_CHECKING
from mypy_boto3_sns.client import SNSClient

# Boto3 client without explicit type annotation (type checker will infer)
def get_sns_client_inferred():
    return boto3.client("sns")

# Boto3 client with explicit type annotation (recommended for type checking)
def get_sns_client_typed() -> SNSClient:
    return boto3.client("sns")

if TYPE_CHECKING:
    # Example usage with type checking
    sns_client: SNSClient = get_sns_client_typed()
    response = sns_client.publish(TopicArn="arn:aws:sns:REGION:ACCOUNT:TOPIC", Message="Hello, SNS!")
    print(f"Message ID: {response['MessageId']}")

# Normal runtime usage (type hints are ignored by the interpreter)
sns_client_runtime = get_sns_client_inferred()
# You would typically have actual topic/message data here, 
# but for a quickstart, we keep it simple.
# Replace with a valid TopicArn for actual execution.
# response_runtime = sns_client_runtime.publish(TopicArn="arn:aws:sns:REGION:ACCOUNT:TOPIC", Message="Hello from runtime!")
# print(f"Runtime Message ID: {response_runtime['MessageId']}")

view raw JSON →