Skip to main content

Type annotations for boto3.S3 1.14.0 service, generated by mypy-boto3-buider 2.1.0

Project description

mypy-boto3-s3

PyPI - mypy-boto3-s3 PyPI - Python Version Docs

Type annotations for boto3.S3 1.14.0 service compatible with mypy, VSCode, PyCharm and other tools.

Generated by mypy-boto3-buider 2.1.0.

More information can be found on boto3-stubs page.

How to install

Make sure you have mypy installed and activated in your IDE.

Install boto3-stubs for S3 service.

python -m pip install boto3-stubs[s3]

How to use

Client annotations

S3Client provides annotations for boto3.client("s3").

import boto3

from mypy_boto3_s3 import S3Client

client: S3Client = boto3.client("s3")

# now client usage is checked by mypy and IDE should provide code auto-complete

# works for session as well
session = boto3.session.Session(region="us-west-1")
session_client: S3Client = session.client("s3")

Paginators annotations

mypy_boto3_s3.paginator module contains type annotations for all paginators.

from mypy_boto3_s3 import S3Client
from mypy_boto3_s3.paginator import (
    ListMultipartUploadsPaginator,
    ListObjectVersionsPaginator,
    ListObjectsPaginator,
    ListObjectsV2Paginator,
    ListPartsPaginator,
)

client: S3Client = boto3.client("s3")

# Explicit type annotations are optional here
# Type should be correctly discovered by mypy and IDEs
# VSCode requires explicit type annotations
list_multipart_uploads_paginator: ListMultipartUploadsPaginator = client.get_paginator("list_multipart_uploads")
list_object_versions_paginator: ListObjectVersionsPaginator = client.get_paginator("list_object_versions")
list_objects_paginator: ListObjectsPaginator = client.get_paginator("list_objects")
list_objects_v2_paginator: ListObjectsV2Paginator = client.get_paginator("list_objects_v2")
list_parts_paginator: ListPartsPaginator = client.get_paginator("list_parts")

Waiters annotations

mypy_boto3_s3.waiter module contains type annotations for all waiters.

from mypy_boto3_s3 import S3Client
from mypy_boto3_s3.waiter import (
    BucketExistsWaiter,
    BucketNotExistsWaiter,
    ObjectExistsWaiter,
    ObjectNotExistsWaiter,
)

client: S3Client = boto3.client("s3")

# Explicit type annotations are optional here
# Type should be correctly discovered by mypy and IDEs
# VSCode requires explicit type annotations
bucket_exists_waiter: BucketExistsWaiter = client.get_waiter("bucket_exists")
bucket_not_exists_waiter: BucketNotExistsWaiter = client.get_waiter("bucket_not_exists")
object_exists_waiter: ObjectExistsWaiter = client.get_waiter("object_exists")
object_not_exists_waiter: ObjectNotExistsWaiter = client.get_waiter("object_not_exists")

Service Resource annotations

S3ServiceResource provides annotations for boto3.resource("s3").

from mypy_boto3_s3 import S3ServiceResource

resource: S3ServiceResource = boto3.resource("s3")

# now resource usage is checked by mypy and IDE should provide code auto-complete

# works for session as well
session = boto3.session.Session(region="us-west-1")
session_resource: S3ServiceResource = session.resource("s3")

Other resources annotations

mypy_boto3_s3.service_resource module contains type annotations for all resources.

from mypy_boto3_s3 import S3ServiceResource
from mypy_boto3_s3.service_resource import (
    Bucket,
    BucketAcl,
    BucketCors,
    BucketLifecycle,
    BucketLifecycleConfiguration,
    BucketLogging,
    BucketNotification,
    BucketPolicy,
    BucketRequestPayment,
    BucketTagging,
    BucketVersioning,
    BucketWebsite,
    MultipartUpload,
    MultipartUploadPart,
    Object,
    ObjectAcl,
    ObjectSummary,
    ObjectVersion,
)

resource: S3ServiceResource = boto3.resource("s3")

# Explicit type annotations are optional here
# Type should be correctly discovered by mypy and IDEs
my_bucket: Bucket = resource.Bucket(...)
my_bucket_acl: BucketAcl = resource.BucketAcl(...)
my_bucket_cors: BucketCors = resource.BucketCors(...)
my_bucket_lifecycle: BucketLifecycle = resource.BucketLifecycle(...)
my_bucket_lifecycle_configuration: BucketLifecycleConfiguration = resource.BucketLifecycleConfiguration(...)
my_bucket_logging: BucketLogging = resource.BucketLogging(...)
my_bucket_notification: BucketNotification = resource.BucketNotification(...)
my_bucket_policy: BucketPolicy = resource.BucketPolicy(...)
my_bucket_request_payment: BucketRequestPayment = resource.BucketRequestPayment(...)
my_bucket_tagging: BucketTagging = resource.BucketTagging(...)
my_bucket_versioning: BucketVersioning = resource.BucketVersioning(...)
my_bucket_website: BucketWebsite = resource.BucketWebsite(...)
my_multipart_upload: MultipartUpload = resource.MultipartUpload(...)
my_multipart_upload_part: MultipartUploadPart = resource.MultipartUploadPart(...)
my_object: Object = resource.Object(...)
my_object_acl: ObjectAcl = resource.ObjectAcl(...)
my_object_summary: ObjectSummary = resource.ObjectSummary(...)
my_object_version: ObjectVersion = resource.ObjectVersion(...)

Collections annotations

mypy_boto3_s3.service_resource module contains type annotations for all S3ServiceResource collections.

from mypy_boto3_s3 import S3ServiceResource
from mypy_boto3_s3.service_resource import (
    ServiceResourceBucketsCollection,
)

resource: S3ServiceResource = boto3.resource("s3")

# Explicit type annotations are optional here
# Type should be correctly discovered by mypy and IDEs
buckets: s3_resources.ServiceResourceBucketsCollection = resource.buckets

Typed dictionations

mypy_boto3_s3.type_defs module contains structures and shapes assembled to typed dictionaries for additional type checking.

from mypy_boto3_s3.type_defs import AbortIncompleteMultipartUploadTypeDef, ...

def get_structure() -> AbortIncompleteMultipartUploadTypeDef:
    return {
      ...
    }

Dynamic type annotations

mypy_boto3 command generates boto3.client/resource type annotations for mypy_boto3_s3 and other installed services.

# Run this command after you add or remove service packages
python -m mypy_boto3

Generated type annotations provide overloads for boto3.client and boto3.resource, boto3.Session.client and boto3.Session.resource functions, so explicit type annotations are not needed.

  • mypy supports function overloads as expected
  • PyCharm also supports function overloads, but consumes a lot of RAM, use carefully if you have many services installed
  • VSCode does not currently support function overloads, use explicit type annotations
import boto3

# Type is discovered correctly by mypy and PyCharm
# VSCode still needs explicit type annotations
client = boto3.client("s3")
resource = boto3.resource("s3")

session_client = boto3.Session().client("s3")
session_resource = boto3.Session().resource("s3")

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mypy-boto3-s3-1.14.0.1.tar.gz (25.5 kB view hashes)

Uploaded Source

Built Distribution

mypy_boto3_s3-1.14.0.1-py3-none-any.whl (25.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page