Type Annotations for boto3 MemoryDB
mypy-boto3-memorydb provides type annotations for the AWS boto3 MemoryDB service, compatible with mypy, VSCode, PyCharm, and other type-checking tools. It offers comprehensive type hints for clients, paginators, waiters, and TypeDefs, ensuring better code quality and developer experience. The current version is 1.42.3 and it's actively maintained as part of the `mypy-boto3-builder` project, which releases updates in sync with boto3 service changes.
Warnings
- breaking Python 3.8 support has been removed in `mypy-boto3-builder` version 8.12.0, which generates `mypy-boto3-memorydb`. Consequently, this package (1.42.3 and newer) requires Python 3.9 or higher.
- breaking Breaking changes were introduced in `mypy-boto3-builder` 8.9.0 regarding TypeDef naming conventions. TypeDefs for packed method arguments use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`), and conflicting `Extra` postfixes were moved (e.g., `CreateDistributionExtraRequestTypeDef` -> `CreateDistributionRequestExtraTypeDef`). This may require updates to existing type hints.
- gotcha This package provides *only type stubs*. You must install the `boto3` library separately for your code to run correctly. `mypy` is also required for static type checking.
- gotcha For PyCharm users, if you experience slow performance due to `Literal` overloads, it is recommended to use the `boto3-stubs-lite` alternative, which provides a more RAM-friendly experience at the cost of requiring more explicit type annotations.
- gotcha For optimal auto-completion and type checking in IDEs like VSCode or with older `mypy` versions, it's often necessary to use explicit type annotations for `boto3.client()` calls, as shown in the quickstart.
- gotcha The version of `mypy-boto3-memorydb` (e.g., 1.42.3) indicates the `boto3` version it provides stubs for. However, the underlying `mypy-boto3-builder` version (e.g., 8.12.0) is independent and refers to the builder's own release cycle and features.
Install
-
pip install mypy-boto3-memorydb boto3 mypy -
pip install 'boto3-stubs[memorydb]' boto3 mypy
Imports
- MemoryDBClient
from mypy_boto3_memorydb.client import MemoryDBClient
- DescribeClustersPaginator
from mypy_boto3_memorydb.paginator import DescribeClustersPaginator
- ResponseMetadataTypeDef
from mypy_boto3_memorydb.type_defs import ResponseMetadataTypeDef
- MemoryDBServiceName
from mypy_boto3_memorydb.literals import MemoryDBServiceName
Quickstart
import boto3
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from mypy_boto3_memorydb.client import MemoryDBClient
from mypy_boto3_memorydb.type_defs import CreateClusterResponseTypeDef
def create_memorydb_cluster(cluster_name: str, node_type: str, num_shards: int) -> CreateClusterResponseTypeDef:
client: MemoryDBClient = boto3.client("memorydb")
response = client.create_cluster(
ClusterName=cluster_name,
NodeType=node_type,
NumShards=num_shards,
Engine="redis",
SnapshotRetentionLimit=7,
SubnetGroupName='default',
ParameterGroupName='default.memorydb.redis6'
)
print(f"Created MemoryDB cluster: {response['Cluster']['ClusterName']}")
return response
# Example usage (ensure you have AWS credentials configured)
# create_memorydb_cluster("my-test-cluster", "db.r6g.large", 1)