Skip to content

Examples#

Index > ElastiCache > Examples

Auto-generated documentation for ElastiCache type annotations stubs module types-boto3-elasticache.

Client#

Implicit type annotations#

Can be used with types-boto3[elasticache] package installed.

Write your ElastiCache code as usual, type checking and code completion should work out of the box.

# ElastiCacheClient usage example

from boto3.session import Session


session = Session()

client = session.client("elasticache")  # (1)
result = client.add_tags_to_resource()  # (2)
  1. client: ElastiCacheClient
  2. result: TagListMessageTypeDef
# DescribeCacheClustersPaginator usage example

from boto3.session import Session


session = Session()
client = session.client("elasticache")  # (1)

paginator = client.get_paginator("describe_cache_clusters")  # (2)
for item in paginator.paginate(...):
    print(item)  # (3)
  1. client: ElastiCacheClient
  2. paginator: DescribeCacheClustersPaginator
  3. item: CacheClusterMessageTypeDef
# CacheClusterAvailableWaiter usage example

from boto3.session import Session


session = Session()
client = session.client("elasticache")  # (1)

waiter = client.get_waiter("cache_cluster_available")  # (2)
waiter.wait()
  1. client: ElastiCacheClient
  2. waiter: CacheClusterAvailableWaiter

Explicit type annotations#

With types-boto3-lite[elasticache] or a standalone types_boto3_elasticache package, you have to explicitly specify client: ElastiCacheClient type annotation.

All other type annotations are optional, as types should be discovered automatically. However, these type annotations can be helpful in your functions and methods.

# ElastiCacheClient usage example with type annotations

from boto3.session import Session

from types_boto3_elasticache.client import ElastiCacheClient
from types_boto3_elasticache.type_defs import TagListMessageTypeDef
from types_boto3_elasticache.type_defs import AddTagsToResourceMessageRequestTypeDef


session = Session()

client: ElastiCacheClient = session.client("elasticache")

kwargs: AddTagsToResourceMessageRequestTypeDef = {...}
result: TagListMessageTypeDef = client.add_tags_to_resource(**kwargs)
# DescribeCacheClustersPaginator usage example with type annotations

from boto3.session import Session

from types_boto3_elasticache.client import ElastiCacheClient
from types_boto3_elasticache.paginator import DescribeCacheClustersPaginator
from types_boto3_elasticache.type_defs import CacheClusterMessageTypeDef


session = Session()
client: ElastiCacheClient = session.client("elasticache")

paginator: DescribeCacheClustersPaginator = client.get_paginator("describe_cache_clusters")
for item in paginator.paginate(...):
    item: CacheClusterMessageTypeDef
    print(item)
# CacheClusterAvailableWaiter usage example with type annotations

from boto3.session import Session

from types_boto3_elasticache.client import ElastiCacheClient
from types_boto3_elasticache.waiter import CacheClusterAvailableWaiter

session = Session()
client: ElastiCacheClient = session.client("elasticache")

waiter: CacheClusterAvailableWaiter = client.get_waiter("cache_cluster_available")
waiter.wait()