Skip to content

Examples#

Index > SQS > Examples

Auto-generated documentation for SQS type annotations stubs module types-aiobotocore-sqs.

Client#

Implicit type annotations#

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

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

# SQSClient usage example

from aioboto3.session import Session


session = Session()

async with session.client("sqs") as client:  # (1)
    result = await client.add_permission()  # (2)
  1. client: SQSClient
  2. result: EmptyResponseMetadataTypeDef
# ListDeadLetterSourceQueuesPaginator usage example

from aioboto3.session import Session


session = Session()

async with session.client("sqs") as client:  # (1)
    paginator = client.get_paginator("list_dead_letter_source_queues")  # (2)
    async for item in paginator.paginate(...):
        print(item)  # (3)
  1. client: SQSClient
  2. paginator: ListDeadLetterSourceQueuesPaginator
  3. item: ListDeadLetterSourceQueuesResultTypeDef

Explicit type annotations#

With types-aioboto3-lite[sqs] or a standalone types_aiobotocore_sqs package, you have to explicitly specify client: SQSClient 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.

# SQSClient usage example with type annotations

from aioboto3.session import Session

from types_aiobotocore_sqs.client import SQSClient
from types_aiobotocore_sqs.type_defs import EmptyResponseMetadataTypeDef
from types_aiobotocore_sqs.type_defs import AddPermissionRequestRequestTypeDef


session = Session()

client: SQSClient
async with session.client("sqs") as client:  # (1)
    kwargs: AddPermissionRequestRequestTypeDef = {...}  # (2)
    result: EmptyResponseMetadataTypeDef = await client.add_permission(**kwargs)  # (3)
  1. client: SQSClient
  2. kwargs: AddPermissionRequestRequestTypeDef
  3. result: EmptyResponseMetadataTypeDef
# ListDeadLetterSourceQueuesPaginator usage example with type annotations

from aioboto3.session import Session

from types_aiobotocore_sqs.client import SQSClient
from types_aiobotocore_sqs.paginator import ListDeadLetterSourceQueuesPaginator
from types_aiobotocore_sqs.type_defs import ListDeadLetterSourceQueuesResultTypeDef


session = Session()

client: SQSClient
async with session.client("sqs") as client:  # (1)
    paginator: ListDeadLetterSourceQueuesPaginator = client.get_paginator("list_dead_letter_source_queues")  # (2)
    async for item in paginator.paginate(...):
        item: ListDeadLetterSourceQueuesResultTypeDef
        print(item)  # (3)
  1. client: SQSClient
  2. paginator: ListDeadLetterSourceQueuesPaginator
  3. item: ListDeadLetterSourceQueuesResultTypeDef

Service Resource#

Implicit type annotations#

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

# SQSServiceResource usage example

from aioboto3.session import Session


session = Session()

async with session.resource("sqs") as resource:  # (1)
    result = resource.Message()  # (2)
  1. resource: SQSServiceResource
  2. result:
# ServiceResourceQueuesCollection usage example

from aioboto3.session import Session


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

collection = resource.queues  # (2)
for item in collection:
    print(item)  # (3)
  1. resource: SQSServiceResource
  2. collection: SQSServiceResource
  3. item: Queue

Explicit type annotations#

With types-aioboto3-lite[sqs] or a standalone types_aiobotocore_sqs package, you have to explicitly specify resource: SQSServiceResource 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.

# SQSServiceResource usage example with type annotations

from aioboto3.session import Session

from types_aiobotocore_sqs.service_resource import SQSServiceResource
from types_aiobotocore_sqs.service_resource import Message


session = Session()

resource: SQSServiceResource
async with session.resource("sqs") as resource:  # (1)
    result: Message = resource.Message() # (2)
  1. resource: SQSServiceResource
  2. result:
# ServiceResourceQueuesCollection usage example with type annotations

from aioboto3.session import Session

from types_aiobotocore_sqs.service_resource import SQSServiceResource
from types_aiobotocore_sqs.service_resource import ServiceResourceQueuesCollection
from types_aiobotocore_sqs.service_resource import Queue


session = Session()

resource: SQSServiceResource
async with session.resource("sqs") as resource:  # (1)
    collection: ServiceResourceQueuesCollection = resource.queues  # (2)
    for item in collection:
        item: Queue
        print(item)  # (3)
  1. resource: SQSServiceResource
  2. collection: SQSServiceResource
  3. item: Queue