Type Annotations for boto3 MemoryDB

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a MemoryDB client with type annotations. The `TYPE_CHECKING` block ensures that the type imports are only used by the type checker and do not introduce runtime dependencies. The client object `client` is explicitly annotated with `MemoryDBClient` for full type-checking and IDE auto-completion. This example creates a MemoryDB cluster.

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)

view raw JSON →