mypy-boto3-ecr Type Stubs

1.42.86 · active · verified Thu Apr 09

mypy-boto3-ecr provides type annotations for the AWS Elastic Container Registry (ECR) service client within `boto3`. These stubs allow static type checkers like MyPy to validate usage of ECR API calls, improving code reliability and developer experience. The current version is 1.42.86, and packages are updated frequently, typically in sync with `boto3` and `botocore` releases.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `mypy-boto3-ecr` to type hint a `boto3` ECR client. It lists your ECR repositories, showing how the `ECRClient` type ensures correct method calls and access to response dict keys.

import boto3
from mypy_boto3_ecr import ECRClient

def list_ecr_repos(ecr_client: ECRClient) -> None:
    """Lists ECR repositories with type hints."""
    print(f"Listing ECR repositories in region {ecr_client.meta.region_name}:")
    try:
        response = ecr_client.describe_repositories()
        repositories = response.get('repositories', [])
        if repositories:
            for repo in repositories:
                print(f"- {repo['repositoryName']} (URI: {repo['repositoryUri']})")
        else:
            print("No ECR repositories found.")
    except Exception as e:
        print(f"Error listing repositories: {e}")

if __name__ == "__main__":
    # Ensure AWS credentials are configured (e.g., via ~/.aws/credentials or env vars)
    # The actual client object comes from boto3, mypy-boto3-ecr provides the type annotation.
    ecr_client: ECRClient = boto3.client(
        "ecr",
        region_name="us-east-1",
        aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', ''),
        aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', '')
    )
    list_ecr_repos(ecr_client)

view raw JSON →