mypy-boto3-ecr Type Stubs
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
- breaking Python 3.8 is no longer supported for any `mypy-boto3` packages, including `mypy-boto3-ecr`, as of `mypy-boto3-builder` version 8.12.0. Users on Python 3.8 will need to upgrade to Python 3.9 or newer.
- gotcha This package only provides type stubs. You must install `boto3` separately for runtime functionality. `mypy-boto3-ecr` does not include the AWS SDK itself.
- gotcha Type stubs are generated for specific `boto3` and `botocore` versions. Mismatches between your installed `boto3` version and the `mypy-boto3-ecr` stubs can lead to incorrect type checking or missing attributes/methods. It's recommended to keep `boto3` and `mypy-boto3-ecr` versions as close as possible.
- breaking As of `mypy-boto3-builder` 8.9.0, some `TypeDef` names were shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). If you manually referenced these types, your code might break.
Install
-
pip install mypy-boto3-ecr
Imports
- ECRClient
from mypy_boto3_ecr import ECRClient
- DescribeRepositoriesPaginator
from mypy_boto3_ecr.paginator import DescribeRepositoriesPaginator
- ImageScanFindingsWaiter
from mypy_boto3_ecr.waiter import ImageScanFindingsWaiter
- RepositoryTypeDef
from mypy_boto3_ecr.type_defs import RepositoryTypeDef
Quickstart
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)