Examples
Auto-generated documentation for S3 type annotations stubs module mypy-boto3-s3.
Client
Implicit type annotations
Can be used with boto3-stubs[s3]
package installed.
Write your S3
code as usual,
type checking and code completion should work out of the box.
from boto3.session import Session
session = Session()
client = session.client("s3") # (1)
result = client.abort_multipart_upload() # (2)
- client: S3Client
- result: AbortMultipartUploadOutputTypeDef
from boto3.session import Session
session = Session()
client = session.client("s3") # (1)
paginator = client.get_paginator("list_multipart_uploads") # (2)
for item in paginator.paginate(...):
print(item) # (3)
- client: S3Client
- paginator: ListMultipartUploadsPaginator
- item: ListMultipartUploadsOutputTypeDef
from boto3.session import Session
session = Session()
client = session.client("s3") # (1)
waiter = client.get_waiter("bucket_exists") # (2)
waiter.wait()
- client: S3Client
- waiter: BucketExistsWaiter
Explicit type annotations
With boto3-stubs-lite[s3]
or a standalone mypy_boto3_s3
package, you have to explicitly specify client: S3Client
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_s3.client import S3Client
from mypy_boto3_s3.type_defs import AbortMultipartUploadOutputTypeDef
from mypy_boto3_s3.type_defs import AbortMultipartUploadRequestRequestTypeDef
session = Session()
client: S3Client = session.client("s3")
kwargs: AbortMultipartUploadRequestRequestTypeDef = {...}
result: AbortMultipartUploadOutputTypeDef = client.abort_multipart_upload(**kwargs)
from boto3.session import Session
from mypy_boto3_s3.client import S3Client
from mypy_boto3_s3.paginator import ListMultipartUploadsPaginator
from mypy_boto3_s3.type_defs import ListMultipartUploadsOutputTypeDef
session = Session()
client: S3Client = session.client("s3")
paginator: ListMultipartUploadsPaginator = client.get_paginator("list_multipart_uploads")
for item in paginator.paginate(...):
item: ListMultipartUploadsOutputTypeDef
print(item)
Service Resource
Implicit type annotations
Can be used with boto3-stubs[s3]
package installed.
from boto3.session import Session
session = Session()
resource = session.resource("s3") # (1)
result = resource.Bucket() # (2)
- resource: S3ServiceResource
- result:
from boto3.session import Session
session = Session()
resource = session.resource("s3") # (1)
collection = resource.buckets # (2)
for item in collection:
print(item) # (3)
- resource: S3ServiceResource
- collection: S3ServiceResource
- item: Bucket
Explicit type annotations
With boto3-stubs-lite[s3]
or a standalone mypy_boto3_s3
package, you have to explicitly specify
resource: S3ServiceResource
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_s3.service_resource import S3ServiceResource
from mypy_boto3_s3.service_resource import ServiceResourceBucketsCollection
from mypy_boto3_s3.service_resource import Bucket
session = Session()
resource: S3ServiceResource = session.resource("s3")
collection: ServiceResourceBucketsCollection = resource.buckets
for item in collection:
item: Bucket
print(item)