mypy-boto3-s3control

1.42.80 · active · verified Sat Apr 11

mypy-boto3-s3control provides type annotations for the AWS Boto3 S3Control client, including explicit type hints for clients, paginators, waiters, and TypeDefs. This significantly enhances static analysis, code completion, and overall developer experience in IDEs like VSCode and PyCharm when working with the AWS SDK for Python (Boto3). It is part of the `mypy-boto3` ecosystem, which generates these stubs based on the latest Boto3 service definitions, with regular updates following Boto3 releases.

Warnings

Install

Imports

Quickstart

This example demonstrates how to initialize a type-hinted `S3ControlClient` and use it to call a method like `list_access_points`. The type annotations ensure that method calls and their parameters/return types are checked statically by tools like MyPy or your IDE, catching potential errors before runtime. Remember to have `boto3` installed alongside `mypy-boto3-s3control`.

import boto3
from mypy_boto3_s3control.client import S3ControlClient
from mypy_boto3_s3control.type_defs import ListAccessPointsResponseTypeDef

def get_s3control_client() -> S3ControlClient:
    """Returns a typed S3Control client."""
    # boto3.client returns an untyped client by default.
    # The explicit type annotation (S3ControlClient) provides type checking.
    client: S3ControlClient = boto3.client("s3control")
    return client

def list_access_points(client: S3ControlClient, account_id: str) -> ListAccessPointsResponseTypeDef:
    """Lists S3 access points with type checking."""
    response: ListAccessPointsResponseTypeDef = client.list_access_points(
        AccountId=account_id
    )
    return response

if __name__ == "__main__":
    # Replace with your AWS account ID
    aws_account_id = "012345678901" # os.environ.get('AWS_ACCOUNT_ID', '012345678901')
    
    s3_control_client = get_s3control_client()
    print(f"S3Control Client type: {type(s3_control_client)}")

    # Example usage (will typically require valid credentials and permissions)
    try:
        access_points = list_access_points(s3_control_client, aws_account_id)
        print(f"Found {len(access_points.get('AccessPointList', []))} S3 access points.")
    except Exception as e:
        print(f"Error listing access points (credentials/permissions might be needed): {e}")

view raw JSON →