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.
from boto3.session import Session
session = Session()
client = session.client("sqs") # (1)
result = client.add_permission() # (2)
- client: SQSClient
- result: EmptyResponseMetadataTypeDef
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)
- client: SQSClient
- paginator: ListDeadLetterSourceQueuesPaginator
- 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.
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)
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.
from boto3.session import Session
session = Session()
resource = session.resource("sqs") # (1)
result = resource.Message() # (2)
- resource: SQSServiceResource
- result:
from boto3.session import Session
session = Session()
resource = session.resource("sqs") # (1)
collection = resource.queues # (2)
for item in collection:
print(item) # (3)
- resource: SQSServiceResource
- collection: SQSServiceResource
- 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.
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)