boto3-stubs-lite
boto3-stubs-lite provides lightweight type annotations for the boto3 library (version 1.42.88 at time of writing), generated by mypy-boto3-builder. It enhances static analysis for boto3 code without requiring installation of full service-specific stub packages, receiving frequent updates aligned with boto3 and mypy-boto3-builder releases.
Warnings
- breaking Support for Python 3.8 was removed in `mypy-boto3-builder` version 8.12.0 (which generates `boto3-stubs-lite`). Users on Python 3.8 will need to upgrade to Python 3.9 or newer.
- breaking The `sms-voice` AWS service was removed in `mypy-boto3-builder` version 8.11.0. Its functionality has been replaced by `pinpoint-sms-voice`.
- gotcha boto3-stubs-lite provides 'lite' type annotations. This means complex TypedDicts for request/response parameters might be simplified or represented as `Any`. For comprehensive, service-specific type definitions with full detail, install `mypy-boto3-servicename` packages (e.g., `mypy-boto3-s3`).
- gotcha Attempting to import types from `mypy_boto3_servicename` (e.g., `from mypy_boto3_s3.client import S3Client`) outside of `if TYPE_CHECKING:` blocks for runtime use will result in `ModuleNotFoundError`, as these modules only contain type stubs, not executable code.
Install
-
pip install boto3-stubs-lite
Imports
- Session
import boto3 session = boto3.session.Session()
- Client
import boto3 s3_client = boto3.client('s3')
Quickstart
import boto3
import os
# boto3-stubs-lite provides type hints for this standard boto3 usage
session = boto3.session.Session(
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'),
region_name=os.environ.get('AWS_REGION', 'us-east-1')
)
s3_client = session.client('s3')
try:
# This call is type-checked by boto3-stubs-lite
response = s3_client.list_buckets()
print(f"Successfully listed {len(response.get('Buckets', []))} buckets.")
except Exception as e:
print(f"Error listing buckets: {e}")
# Example of using a resource (also typed)
# s3_resource = session.resource('s3')
# bucket = s3_resource.Bucket('my-example-bucket')
# print(f"Bucket name: {bucket.name}")