Type Annotations for boto3 CodeGuru Reviewer

1.42.3 · active · verified Sat Apr 11

mypy-boto3-codeguru-reviewer provides type annotations for the boto3 AWS SDK, specifically for the CodeGuru Reviewer service. It enhances static type checking with tools like mypy, improves IDE autocomplete, and helps catch potential bugs at development time. The library is currently at version 1.42.3 and is actively maintained with frequent updates following boto3 releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a type-hinted CodeGuruReviewer client and call a basic operation, `list_repository_associations`, with its response also fully type-hinted. Ensure `boto3` and `mypy` are installed alongside this stub package. For actual execution, valid AWS credentials and region must be configured.

import boto3
from mypy_boto3_codeguru_reviewer.client import CodeGuruReviewerClient
from mypy_boto3_codeguru_reviewer.type_defs import ListRepositoryAssociationsResponseTypeDef
import os

def get_reviewer_client() -> CodeGuruReviewerClient:
    """Returns a type-hinted CodeGuruReviewer client."""
    # Ensure AWS_REGION is set in environment or configure it explicitly
    return boto3.client("codeguru-reviewer", region_name=os.environ.get("AWS_REGION", "us-east-1"))

def list_reviewer_associations() -> ListRepositoryAssociationsResponseTypeDef:
    """Lists CodeGuru Reviewer repository associations with type hints."""
    client: CodeGuruReviewerClient = get_reviewer_client()
    response: ListRepositoryAssociationsResponseTypeDef = client.list_repository_associations()
    print("CodeGuru Reviewer Repository Associations:")
    for association in response.get("RepositoryAssociationSummaries", []):
        print(f"- {association.get('Name')} (State: {association.get('State')})")
    return response

if __name__ == "__main__":
    # Set dummy environment variables if not already set, for demonstration purposes.
    # In a real scenario, use proper AWS credential configuration.
    if not os.environ.get("AWS_ACCESS_KEY_ID"):
        os.environ["AWS_ACCESS_KEY_ID"] = "TEST_KEY"
    if not os.environ.get("AWS_SECRET_ACCESS_KEY"):
        os.environ["AWS_SECRET_ACCESS_KEY"] = "TEST_SECRET"
    if not os.environ.get("AWS_REGION"):
        os.environ["AWS_REGION"] = "us-east-1"

    try:
        list_reviewer_associations()
    except Exception as e:
        # Boto3 client operations will fail if credentials are not valid,
        # but mypy type checking will still work. 
        print(f"An error occurred during runtime: {e}")
        print("Please ensure your AWS credentials and region are configured correctly for actual execution.")

view raw JSON →