Type Stubs for Boto (AWS SDK v2)
types-boto provides static type annotations for the `boto` library (version 2.x), enabling type checkers like MyPy to validate `boto` code. It is part of the community-driven `typeshed` project and is updated regularly to match `boto`'s API, though `boto` itself is an older AWS SDK. The current version is 2.49.18.20241019, with its release cadence following `typeshed`'s updates.
Warnings
- gotcha `types-boto` provides stubs for the older `boto` library (version 2.x). If you are using the modern AWS SDK for Python (`boto3`), you should install `types-boto3` instead.
- gotcha This library provides static type hints only. It does not add any runtime functionality or change how `boto` behaves at execution. A type checker like MyPy or pyright is required to utilize these stubs for code validation.
- deprecated The `boto` library itself (version 2.x), for which `types-boto` provides stubs, is considered legacy. AWS recommends `boto3` for new development. While `types-boto` helps maintain older `boto` code, new projects should generally use `boto3`.
Install
-
pip install types-boto
Imports
- S3Connection
from boto.s3.connection import S3Connection
Quickstart
import os
import boto.s3.connection
import boto.ec2.connection
# types-boto provides type hints for these objects,
# allowing type checkers like MyPy to validate your code.
# Credentials should ideally come from environment variables or a secure configuration.
# For a runnable example, we use os.environ.get with placeholders.
aws_access_key = os.environ.get('AWS_ACCESS_KEY_ID', 'YOUR_ACCESS_KEY_GOES_HERE')
aws_secret_key = os.environ.get('AWS_SECRET_ACCESS_KEY', 'YOUR_SECRET_KEY_GOES_HERE')
try:
# Example: S3 connection with type hint from types-boto
s3_conn: boto.s3.connection.S3Connection = boto.s3.connection.S3Connection(
aws_access_key_id=aws_access_key,
aws_secret_access_key=aws_secret_key
)
print(f"S3 connection created (type checked by types-boto): {s3_conn}")
# Example: EC2 connection with type hint from types-boto
ec2_conn: boto.ec2.connection.EC2Connection = boto.ec2.connection.EC2Connection(
aws_access_key_id=aws_access_key,
aws_secret_access_key=aws_secret_key
)
print(f"EC2 connection created (type checked by types-boto): {ec2_conn}")
# In a real application, you would perform operations here, e.g.:
# buckets = s3_conn.get_all_buckets()
# print(f"Found {len(buckets)} S3 buckets.")
except Exception as e:
print(f"Failed to create boto connections. Ensure 'boto' is installed and credentials are set: {e}")
print("Note: types-boto only provides type hints, it does not enable runtime functionality.")