mypy-boto3-elasticache
mypy-boto3-elasticache provides comprehensive type annotations for the `boto3` ElastiCache service. It enables static type checking with tools like MyPy for `boto3` users, improving code reliability and developer experience. The library is generated by `mypy-boto3-builder` and is updated frequently, often in sync with `boto3` releases and builder improvements. The current version is 1.42.81.
Warnings
- breaking Starting with `mypy-boto3-builder` version 8.12.0, support for Python 3.8 has been removed for all generated packages, including `mypy-boto3-elasticache`. Minimum required Python version is now 3.9.
- breaking Beginning with `mypy-boto3-builder` version 8.9.0, there were breaking changes to `TypeDef` naming conventions (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`). If you explicitly import and use these generated types, your code may require updates.
- gotcha These packages provide only type stubs. Do not attempt to instantiate clients or resources directly from `mypy_boto3_elasticache` modules at runtime. Always use `boto3.client('elasticache')` or `boto3.resource('elasticache')` for runtime operations.
- gotcha AWS service names can change or be deprecated (e.g., `sms-voice` was replaced by `pinpoint-sms-voice`). While this specific change doesn't affect ElastiCache, be aware that service module names in `mypy-boto3` packages may evolve with AWS service updates.
Install
-
pip install mypy-boto3-elasticache
Imports
- ElastiCacheClient
from mypy_boto3_elasticache.client import ElastiCacheClient import boto3 client: ElastiCacheClient = boto3.client('elasticache') - DescribeCacheClustersResultTypeDef
from mypy_boto3_elasticache.type_defs import DescribeCacheClustersResultTypeDef
Quickstart
import boto3
import os
from mypy_boto3_elasticache.client import ElastiCacheClient
from mypy_boto3_elasticache.type_defs import DescribeCacheClustersResultTypeDef
# mypy-boto3-elasticache provides type annotations for boto3.
# The actual boto3 library handles runtime interactions.
aws_region = os.environ.get("AWS_REGION", "us-east-1")
try:
# Initialize ElastiCache client with type annotation for improved type checking
client: ElastiCacheClient = boto3.client("elasticache", region_name=aws_region)
# Example: Describe cache clusters
# The return type is automatically inferred by MyPy if stubs are installed,
# but can be explicitly annotated for clarity.
response: DescribeCacheClustersResultTypeDef = client.describe_cache_clusters()
print(f"Successfully described {len(response.get('CacheClusters', []))} ElastiCache clusters.")
for cluster in response.get('CacheClusters', []):
print(f" - {cluster['CacheClusterId']} ({cluster['Engine']})")
except Exception as e:
print(f"An error occurred: {e}")
print("Ensure AWS credentials and region are configured (e.g., via environment variables or ~/.aws/credentials).")