{"id":2132,"library":"mypy-boto3-sns","title":"Mypy Boto3 SNS Type Stubs","description":"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.","status":"active","version":"1.42.3","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["aws","boto3","sns","mypy","type-hinting","stubs","static-analysis"],"install":[{"cmd":"pip install mypy-boto3-sns boto3 mypy","lang":"bash","label":"Install with Boto3 and Mypy"}],"dependencies":[{"reason":"Runtime dependency for the AWS SDK being type-hinted.","package":"boto3"},{"reason":"Static type checker, the primary consumer of these stubs.","package":"mypy"}],"imports":[{"note":"For explicit type annotations of the SNS client.","symbol":"SNSClient","correct":"from mypy_boto3_sns.client import SNSClient"},{"note":"For explicit type annotations of the SNS service resource.","symbol":"SNSServiceResource","correct":"from mypy_boto3_sns.service_resource import SNSServiceResource"},{"note":"For explicit type annotations of specific TypeDefs, often used for method arguments.","symbol":"AddPermissionInputTopicAddPermissionTypeDef","correct":"from mypy_boto3_sns.type_defs import AddPermissionInputTopicAddPermissionTypeDef"}],"quickstart":{"code":"import boto3\nfrom typing import TYPE_CHECKING\nfrom mypy_boto3_sns.client import SNSClient\n\n# Boto3 client without explicit type annotation (type checker will infer)\ndef get_sns_client_inferred():\n    return boto3.client(\"sns\")\n\n# Boto3 client with explicit type annotation (recommended for type checking)\ndef get_sns_client_typed() -> SNSClient:\n    return boto3.client(\"sns\")\n\nif TYPE_CHECKING:\n    # Example usage with type checking\n    sns_client: SNSClient = get_sns_client_typed()\n    response = sns_client.publish(TopicArn=\"arn:aws:sns:REGION:ACCOUNT:TOPIC\", Message=\"Hello, SNS!\")\n    print(f\"Message ID: {response['MessageId']}\")\n\n# Normal runtime usage (type hints are ignored by the interpreter)\nsns_client_runtime = get_sns_client_inferred()\n# You would typically have actual topic/message data here, \n# but for a quickstart, we keep it simple.\n# Replace with a valid TopicArn for actual execution.\n# response_runtime = sns_client_runtime.publish(TopicArn=\"arn:aws:sns:REGION:ACCOUNT:TOPIC\", Message=\"Hello from runtime!\")\n# print(f\"Runtime Message ID: {response_runtime['MessageId']}\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade to Python 3.9 or higher. If unable to upgrade Python, pin `mypy-boto3-sns` to an older compatible version.","message":"Removed support for Python 3.8. The `mypy-boto3-builder` 8.12.0, which generated `mypy-boto3-sns` 1.42.3, no longer supports Python 3.8. Users on Python 3.8 must either upgrade their Python version or use an older version of `mypy-boto3-sns`.","severity":"breaking","affected_versions":">=1.42.3 (builder >=8.12.0)"},{"fix":"Review your code for direct imports or usage of `TypeDef` names and update them according to the new naming conventions. Consult the specific service's documentation for exact new names.","message":"Breaking changes to `TypeDef` naming conventions. In `mypy-boto3-builder` 8.9.0 (and potentially affecting later versions), `TypeDef` names for packed method arguments were shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). Additionally, conflicting `Extra` postfixes were moved to the end of the name (e.g., `CreateDistributionExtraRequestTypeDef` became `CreateDistributionRequestExtraTypeDef`). While not specific to SNS in the release notes, this applies to `[services]` generated by the builder and may affect users relying on specific `TypeDef` names.","severity":"breaking","affected_versions":">=0.9.0 (builder >=8.9.0)"},{"fix":"Ensure `boto3` is installed alongside `mypy-boto3-sns`. Do not expect `mypy-boto3-sns` to provide actual AWS SDK functionality.","message":"The library only provides type hints; it does not add runtime functionality to `boto3`. `mypy-boto3-sns` is a stub package that helps static type checkers (like mypy) understand `boto3`'s API. It is not a replacement for `boto3` and has no runtime impact on your application.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Set all types to `object` in the `else` block for `if TYPE_CHECKING:` statements to provide a fallback for `pylint`. Example: `if TYPE_CHECKING: from mypy_boto3_sns.client import SNSClient else: SNSClient = object`","message":"`pylint` may complain about undefined variables when using `typing.TYPE_CHECKING` for conditional imports. This is a known issue.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Choose one installation strategy and stick to it. For individual service stubs, `pip install mypy-boto3-sns` is appropriate. For a more integrated approach, `pip install 'boto3-stubs[sns]'` is another option.","message":"There are two main ways to install boto3 stubs: `mypy-boto3-sns` (standalone) or `boto3-stubs[sns]` (part of the `boto3-stubs` meta-package). Confusing these or mixing installations can lead to unexpected type-checking behavior.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}