Type Annotations for boto3 (full)
types-boto3-full provides comprehensive type annotations for the popular AWS SDK for Python, boto3. It is an 'all-in-one' package that bundles all service-specific type stubs generated by mypy-boto3-builder. This allows for static type checking of boto3 code using tools like MyPy, catching potential errors before runtime. The current version is 1.42.88, matching the boto3 version it provides stubs for, and is frequently updated in sync with boto3 releases and mypy-boto3-builder enhancements.
Warnings
- breaking Python 3.8 support has been removed as of `mypy-boto3-builder` version 8.12.0 (which generates `types-boto3-full` 1.42.x and above).
- gotcha `types-boto3-full` provides type stubs only. You must also install `boto3` separately for your code to run at runtime.
- breaking The `sms-voice` service was removed in `mypy-boto3-builder` 8.11.0 (generating `types-boto3-full` 1.41.x+). It is no longer supported; use `pinpoint-sms-voice` instead.
- breaking TypedDict naming conventions were changed in `mypy-boto3-builder` 8.9.0 (generating `types-boto3-full` 1.39.x+), potentially shortening names or reordering suffixes (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`).
- gotcha The package `types-boto3-full` itself is not meant to be imported directly at runtime. It's a collection of stub files that a type checker (like MyPy) uses to understand `boto3`'s types.
Install
-
pip install types-boto3-full boto3
Imports
- S3Client
from boto3_stubs.s3.client import S3Client
- Session
from boto3_stubs.session import Session
Quickstart
from typing import TYPE_CHECKING
import boto3
import os
# Conditionally import type stubs only for type checking
if TYPE_CHECKING:
from boto3_stubs.s3.client import S3Client
from boto3_stubs.session import Session
# Instantiate a boto3 session (runtime code)
session: 'Session' = boto3.session.Session(
region_name=os.environ.get('AWS_REGION', 'us-east-1'),
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY'),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET')
)
# Get an S3 client and type-hint it
s3_client: 'S3Client' = session.client('s3')
try:
# This call will be type-checked by MyPy
buckets = s3_client.list_buckets()
print(f"Successfully listed {len(buckets.get('Buckets', []))} S3 buckets.")
except Exception as e:
print(f"Error listing S3 buckets: {e}")
# To type-check this file, run:
# pip install mypy
# mypy your_script_name.py