Skip to content

Examples#

Index > SNS > Examples

Auto-generated documentation for SNS type annotations stubs module types-aiobotocore-sns.

Client#

Implicit type annotations#

Can be used with types-aioboto3[sns] package installed.

Write your SNS code as usual, type checking and code completion should work out of the box.

# SNSClient usage example

from aioboto3.session import Session


session = Session()

async with session.client("sns") as client:  # (1)
    result = await client.add_permission()  # (2)
  1. client: SNSClient
  2. result: EmptyResponseMetadataTypeDef
# ListEndpointsByPlatformApplicationPaginator usage example

from aioboto3.session import Session


session = Session()

async with session.client("sns") as client:  # (1)
    paginator = client.get_paginator("list_endpoints_by_platform_application")  # (2)
    async for item in paginator.paginate(...):
        print(item)  # (3)
  1. client: SNSClient
  2. paginator: ListEndpointsByPlatformApplicationPaginator
  3. item: ListEndpointsByPlatformApplicationResponseTypeDef

Explicit type annotations#

With types-aioboto3-lite[sns] or a standalone types_aiobotocore_sns package, you have to explicitly specify client: SNSClient type annotation.

All other type annotations are optional, as types should be discovered automatically. However, these type annotations can be helpful in your functions and methods.

# SNSClient usage example with type annotations

from aioboto3.session import Session

from types_aiobotocore_sns.client import SNSClient
from types_aiobotocore_sns.type_defs import EmptyResponseMetadataTypeDef
from types_aiobotocore_sns.type_defs import AddPermissionInputRequestTypeDef


session = Session()

client: SNSClient
async with session.client("sns") as client:  # (1)
    kwargs: AddPermissionInputRequestTypeDef = {...}  # (2)
    result: EmptyResponseMetadataTypeDef = await client.add_permission(**kwargs)  # (3)
  1. client: SNSClient
  2. kwargs: AddPermissionInputRequestTypeDef
  3. result: EmptyResponseMetadataTypeDef
# ListEndpointsByPlatformApplicationPaginator usage example with type annotations

from aioboto3.session import Session

from types_aiobotocore_sns.client import SNSClient
from types_aiobotocore_sns.paginator import ListEndpointsByPlatformApplicationPaginator
from types_aiobotocore_sns.type_defs import ListEndpointsByPlatformApplicationResponseTypeDef


session = Session()

client: SNSClient
async with session.client("sns") as client:  # (1)
    paginator: ListEndpointsByPlatformApplicationPaginator = client.get_paginator("list_endpoints_by_platform_application")  # (2)
    async for item in paginator.paginate(...):
        item: ListEndpointsByPlatformApplicationResponseTypeDef
        print(item)  # (3)
  1. client: SNSClient
  2. paginator: ListEndpointsByPlatformApplicationPaginator
  3. item: ListEndpointsByPlatformApplicationResponseTypeDef

Service Resource#

Implicit type annotations#

Can be used with types-aioboto3[sns] package installed.

# SNSServiceResource usage example

from aioboto3.session import Session


session = Session()

async with session.resource("sns") as resource:  # (1)
    result = resource.PlatformApplication()  # (2)
  1. resource: SNSServiceResource
  2. result:
# ServiceResourcePlatformApplicationsCollection usage example

from aioboto3.session import Session


session = Session()
resource = session.resource("sns")  # (1)

collection = resource.platform_applications  # (2)
for item in collection:
    print(item)  # (3)
  1. resource: SNSServiceResource
  2. collection: SNSServiceResource
  3. item: PlatformApplication

Explicit type annotations#

With types-aioboto3-lite[sns] or a standalone types_aiobotocore_sns package, you have to explicitly specify resource: SNSServiceResource type annotation.

All other type annotations are optional, as types should be discovered automatically. However, these type annotations can be helpful in your functions and methods.

# SNSServiceResource usage example with type annotations

from aioboto3.session import Session

from types_aiobotocore_sns.service_resource import SNSServiceResource
from types_aiobotocore_sns.service_resource import PlatformApplication


session = Session()

resource: SNSServiceResource
async with session.resource("sns") as resource:  # (1)
    result: PlatformApplication = resource.PlatformApplication() # (2)
  1. resource: SNSServiceResource
  2. result:
# ServiceResourcePlatformApplicationsCollection usage example with type annotations

from aioboto3.session import Session

from types_aiobotocore_sns.service_resource import SNSServiceResource
from types_aiobotocore_sns.service_resource import ServiceResourcePlatformApplicationsCollection
from types_aiobotocore_sns.service_resource import PlatformApplication


session = Session()

resource: SNSServiceResource
async with session.resource("sns") as resource:  # (1)
    collection: ServiceResourcePlatformApplicationsCollection = resource.platform_applications  # (2)
    for item in collection:
        item: PlatformApplication
        print(item)  # (3)
  1. resource: SNSServiceResource
  2. collection: SNSServiceResource
  3. item: PlatformApplication