Botocore Stubs

1.42.41 · active · verified Sat Mar 28

Botocore Stubs provides comprehensive type annotations and code completion for the `botocore` library, the low-level interface to Amazon Web Services. This package, part of the `mypy_boto3_builder` project, is designed to enhance static type analysis with tools like MyPy and Pyright, and improve IDE auto-completion for `botocore`'s dynamically generated classes. It is actively maintained with versions aligned to corresponding `botocore` releases, with the current version being 1.42.41.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a botocore session and create an S3 client. With `botocore-stubs` installed, type checkers like MyPy or Pyright will provide full code completion and static analysis for the `s3_client` object and its methods, such as `list_buckets()`.

import os
from botocore.session import Session
from botocore.client import S3Client # For type hinting the client

def get_s3_client() -> S3Client:
    """
    Returns a typed S3 client from botocore. 
    botocore-stubs provides the type hints for S3Client.
    """
    # Ensure AWS credentials are set up, e.g., via environment variables
    # AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION
    session = Session()
    # The return type of session.create_client('s3') is dynamically generated.
    # The type checker uses botocore-stubs to infer it as S3Client.
    return session.create_client('s3', region_name=os.environ.get('AWS_REGION', 'us-east-1'))

if __name__ == "__main__":
    s3_client = get_s3_client()
    try:
        # This call will have type hints thanks to botocore-stubs
        response = s3_client.list_buckets()
        print("Successfully listed S3 buckets:")
        for bucket in response.get('Buckets', []):
            print(f"- {bucket['Name']}")
    except Exception as e:
        print(f"Error listing S3 buckets: {e}")
        print("Ensure you have AWS credentials configured (e.g., AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION environment variables).")

view raw JSON →