Skip to content

Examples#

Index > SQS > Examples

Auto-generated documentation for SQS type annotations stubs module mypy-boto3-sqs.

Client#

Implicit type annotations#

Can be used with boto3-stubs[sqs] package installed.

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

# SQSClient usage example

from boto3.session import Session


session = Session()

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

from boto3.session import Session


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

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

Explicit type annotations#

With boto3-stubs-lite[sqs] or a standalone mypy_boto3_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 boto3.session import Session

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


session = Session()

client: SQSClient = session.client("sqs")

kwargs: AddPermissionRequestRequestTypeDef = {...}
result: EmptyResponseMetadataTypeDef = client.add_permission(**kwargs)
# ListDeadLetterSourceQueuesPaginator usage example with type annotations

from boto3.session import Session

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


session = Session()
client: SQSClient = session.client("sqs")

paginator: ListDeadLetterSourceQueuesPaginator = client.get_paginator("list_dead_letter_source_queues")
for item in paginator.paginate(...):
    item: ListDeadLetterSourceQueuesResultTypeDef
    print(item)

Service Resource#

Implicit type annotations#

Can be used with boto3-stubs[sqs] package installed.

# SQSServiceResource usage example

from boto3.session import Session


session = Session()

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

from boto3.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 boto3-stubs-lite[sqs] or a standalone mypy_boto3_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 boto3.session import Session

from mypy_boto3_sqs.service_resource import SQSServiceResource
from mypy_boto3_sqs.service_resource import Message


session = Session()

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

from boto3.session import Session

from mypy_boto3_sqs.service_resource import SQSServiceResource
from mypy_boto3_sqs.service_resource import ServiceResourceQueuesCollection
from mypy_boto3_sqs.service_resource import Queue


session = Session()

resource: SQSServiceResource = session.resource("sqs")

collection: ServiceResourceQueuesCollection = resource.queues
for item in collection:
    item: Queue
    print(item)