Skip to content

Examples#

Index > SQS > Examples

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

Client#

Implicit type annotations#

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

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

Client method usage example#

# 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

Paginator usage example#

# 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 types-boto3-lite[sqs] or a standalone types_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.

Client method usage example#

# SQSClient usage example with type annotations

from boto3.session import Session

from types_boto3_sqs.client import SQSClient
from types_boto3_sqs.type_defs import EmptyResponseMetadataTypeDef
from types_boto3_sqs.type_defs import AddPermissionRequestTypeDef


session = Session()

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

kwargs: AddPermissionRequestTypeDef = {...}
result: EmptyResponseMetadataTypeDef = client.add_permission(**kwargs)

Paginator usage example#

# ListDeadLetterSourceQueuesPaginator usage example with type annotations

from boto3.session import Session

from types_boto3_sqs.client import SQSClient
from types_boto3_sqs.paginator import ListDeadLetterSourceQueuesPaginator
from types_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 types-boto3[sqs] package installed.

ServiceResource method usage example#

# SQSServiceResource usage example

from boto3.session import Session


session = Session()

resource = session.resource("sqs")  # (1)
result = resource.create_queue(...)  # (2)
  1. resource: SQSServiceResource
  2. result: Queue

Collection usage example#

# 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: ServiceResourceQueuesCollection
  3. item: Queue

Explicit type annotations#

With types-boto3-lite[sqs] or a standalone types_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.

ServiceResource method usage example#

# SQSServiceResource usage example with type annotations

from boto3.session import Session

from types_boto3_sqs.service_resource import SQSServiceResource
from types_boto3_sqs.service_resource import Queue
from types_boto3_sqs.type_defs import CreateQueueRequestServiceResourceCreateQueueTypeDef


session = Session()

resource: SQSServiceResource = session.resource("sqs")
kwargs: CreateQueueRequestServiceResourceCreateQueueTypeDef = {...}  # (2)
result: Queue = resource.create_queue(**kwargs)
  1. resource: SQSServiceResource
  2. kwargs: CreateQueueRequestServiceResourceCreateQueueTypeDef
  3. result: Queue

Collection usage example#

# ServiceResourceQueuesCollection usage example with type annotations

from boto3.session import Session

from types_boto3_sqs.service_resource import SQSServiceResource
from types_boto3_sqs.service_resource import ServiceResourceQueuesCollection
from types_boto3_sqs.service_resource import Queue


session = Session()

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

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