Type Annotations for boto3 EKS
mypy-boto3-eks provides high-quality type annotations for the boto3 EKS client and service-specific types, enabling static type checking with Mypy and enhancing IDE autocompletion. It is part of the larger `mypy-boto3` ecosystem, generated by `mypy-boto3-builder`. The current version is 1.42.85, and releases are frequent, typically tracking `boto3` versions closely.
Warnings
- breaking Starting with `mypy-boto3-builder` version 8.12.0 (which generates `mypy-boto3-eks` packages), Python 3.8 is no longer supported. Projects requiring type annotations for EKS must use Python 3.9 or newer.
- gotcha The version of `mypy-boto3-eks` is closely tied to the `boto3` version it provides stubs for. Using mismatched versions (e.g., `mypy-boto3-eks==1.42.85` with `boto3==1.28.0`) can lead to Mypy errors or incorrect type hints.
- breaking Internal type definition (TypeDef) names for request/response structures can change across major builder versions (e.g., `CreateDistributionRequestRequestTypeDef` becoming `CreateDistributionRequestTypeDef`).
- gotcha Service API changes in underlying `boto3` (e.g., service renames like `sms-voice` to `pinpoint-sms-voice` or changes in API parameters) are reflected in the stub packages. This can lead to type errors if your code calls deprecated or renamed methods/services.
Install
-
pip install mypy-boto3-eks
Imports
- EKSClient
from mypy_boto3_eks.client import EKSClient
- ListClustersResponseTypeDef
from mypy_boto3_eks.type_defs import ListClustersResponseTypeDef
Quickstart
import boto3
from mypy_boto3_eks.client import EKSClient
from mypy_boto3_eks.type_defs import ListClustersResponseTypeDef
# Initialize a Boto3 EKS client with type hinting from mypy-boto3-eks
client: EKSClient = boto3.client("eks")
# Call a client method and ensure the response is correctly typed
response: ListClustersResponseTypeDef = client.list_clusters()
print("Found EKS clusters:")
for cluster in response.get("clusters", []):
print(f"- {cluster['name']} (version: {cluster.get('version', 'N/A')})")
# mypy will now provide checks for attribute access and types
# Example: if 'nextToken' is present, its type is known
if 'nextToken' in response:
next_token: str = response['nextToken']
print(f"Next Token: {next_token}")