Type Stubs for Boto (AWS SDK v2)

2.49.18.20241019 · active · verified Mon Apr 13

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

Install

Imports

Quickstart

This quickstart demonstrates importing and instantiating `boto` (v2) connections. `types-boto` provides the type hints for `boto.s3.connection.S3Connection` and `boto.ec2.connection.EC2Connection`, enabling static type checkers to validate your code. Remember to replace placeholder credentials with actual ones or environment variables.

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.")

view raw JSON →