mypy-boto3-codecommit

1.42.3 · active · verified Sat Apr 11

mypy-boto3-codecommit provides type annotations for the boto3 CodeCommit service, enabling static type checking with mypy. It's automatically generated from AWS service definitions, ensuring up-to-date and accurate type hints. The current version is 1.42.3, with releases closely tracking boto3 and mypy-boto3-builder updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a type-hinted boto3 CodeCommit client and use one of its methods. Running `mypy app.py` against this script will leverage the installed type stubs to check for type correctness, enhancing development reliability.

import os
import boto3
from mypy_boto3_codecommit.client import CodeCommitClient
from botocore.exceptions import ClientError

# Ensure AWS_REGION is set in environment variables or provide region_name directly
region = os.environ.get("AWS_REGION", "us-east-1")

try:
    # Initialize a typed CodeCommit client
    client: CodeCommitClient = boto3.client("codecommit", region_name=region)
    print(f"Listing repositories in region: {region}...")
    
    # Use a client method with type hints
    response = client.list_repositories(
        sortBy="repositoryName",
        order="ascending"
    )
    
    repositories = response.get("repositories", [])
    if repositories:
        print(f"Found {len(repositories)} repositories:")
        for repo in repositories[:3]: # Limit output for brevity
            print(f"- {repo['repositoryName']} (ID: {repo['repositoryId']})")
    else:
        print("No repositories found.")
        
except ClientError as e:
    print(f"AWS Client Error: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

# To verify types, save this code as `app.py` and run:
# mypy app.py

view raw JSON →