boto3-stubs Type Annotations for AWS SDK for Python
boto3-stubs provides comprehensive type annotations for the `boto3` AWS SDK for Python, enabling static type checking with tools like MyPy and PyRight, and enhancing IDE auto-completion. It is generated by `mypy-boto3-builder` and is actively maintained with frequent updates, typically aligning with `boto3` releases to ensure compatibility with the latest AWS services and features.
Warnings
- breaking Dropped Python 3.8 support. As of `mypy-boto3-builder` version 8.12.0, Python 3.8 is no longer supported for any `boto3-stubs` packages. Projects must use Python 3.9 or newer.
- breaking Migration to PEP 561 packages. This changes how stubs are packaged and distributed, potentially affecting build systems or direct imports from stub packages.
- breaking Service `sms-voice` was removed and replaced by `pinpoint-sms-voice`. If you were using `sms-voice` types, they are no longer generated.
- breaking TypeDef naming conventions changed for packed method arguments and conflicting names. TypeDefs like `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`, and `CreateDistributionExtraRequestTypeDef` became `CreateDistributionRequestExtraTypeDef`.
- gotcha This library only provides type annotations. You must still install `boto3` (and `botocore`) for your code to actually run. `boto3-stubs` does not include the AWS SDK itself.
- gotcha PyCharm's performance can be slow with `Literal` overloads. It is recommended to use `boto3-stubs-lite` or external type checkers (MyPy/PyRight) if you experience high CPU usage or slow performance in PyCharm.
Install
-
pip install boto3-stubs -
pip install 'boto3-stubs[s3]' -
pip install 'boto3-stubs[essential]' -
pip install boto3-stubs-lite
Imports
- Session
import boto3; from boto3.session import Session
- S3Client
from mypy_boto3_s3.client import S3Client
- Bucket
from mypy_boto3_s3.service_resource import Bucket
Quickstart
import boto3
from mypy_boto3_s3.client import S3Client
import os
def list_s3_buckets(region_name: str = os.environ.get('AWS_REGION', 'us-east-1')) -> list[str]:
"""Lists S3 bucket names with type hints."""
# boto3-stubs automatically provides type hints for client() and resource() calls
s3_client: S3Client = boto3.client("s3", region_name=region_name)
response = s3_client.list_buckets()
bucket_names = [bucket['Name'] for bucket in response.get('Buckets', [])]
return bucket_names
if __name__ == "__main__":
print(f"S3 Buckets: {list_s3_buckets()}")