mypy-boto3-ecs
mypy-boto3-ecs provides type annotations for the AWS boto3 ECS (Elastic Container Service) client, resources, and paginators. It is part of the `mypy-boto3` project, which generates stubs for all boto3 services. The current version is 1.42.88, with frequent releases synchronized with new `boto3` versions and `mypy-boto3-builder` updates.
Warnings
- breaking Python 3.8 support has been removed for all `mypy-boto3` packages with `mypy-boto3-builder` version 8.12.0 and above. Ensure your environment uses Python 3.9 or higher.
- gotcha `mypy-boto3-ecs` provides only type stubs. You must install `boto3` separately for your code to run. It's a common mistake to install only the stub package.
- breaking TypeDef naming conventions changed in `mypy-boto3-builder` 8.9.0. Specifically, argument TypeDefs use shorter names, and conflicting TypeDef `Extra` postfixes were moved. This might require updating type annotation references in your codebase.
- gotcha The `mypy-boto3` stub packages, including `mypy-boto3-ecs`, migrated to PEP 561 compliance with `mypy-boto3-builder` 8.12.0. While this is an improvement for type checker discovery, some legacy tools or build systems might need minor adjustments.
- gotcha These stubs are designed for use with `mypy`. While other type checkers might work, `mypy` is the primary target and often yields the most accurate results.
Install
-
pip install boto3 mypy-boto3-ecs mypy
Imports
- ECSClient
from mypy_boto3_ecs.client import ECSClient
- ECSResource
from mypy_boto3_ecs.service_resource import ECSResource
- ListClustersPaginator
from mypy_boto3_ecs.paginator import ListClustersPaginator
Quickstart
import boto3
from mypy_boto3_ecs.client import ECSClient
from typing import TYPE_CHECKING
# Ensure boto3 is installed: pip install boto3 mypy-boto3-ecs
if TYPE_CHECKING:
# This block is only for type checking, not runtime execution
client: ECSClient = boto3.client("ecs")
# Example usage with type hints
response = client.list_clusters()
for cluster in response.get("clusters", []):
print(f"Cluster ARN: {cluster.get('clusterArn')}")
else:
# Runtime code without explicit type hints (mypy will still check)
client = boto3.client("ecs")
response = client.list_clusters()
for cluster in response.get("clusters", []):
print(f"Cluster Name: {cluster.get('clusterName')}")