Type Annotations for boto3 (full)

1.42.88 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to use types-boto3-full for static type checking with boto3. It shows conditional imports for type stubs and then applies them to a standard boto3 client interaction. Ensure you have `boto3` and `mypy` installed alongside `types-boto3-full`.

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

view raw JSON →