Type annotations for boto3 DynamoDB

1.42.73 · active · verified Sat Apr 11

types-boto3-dynamodb provides comprehensive type annotations for the `boto3` AWS SDK's DynamoDB service. It is part of the `types-boto3` project and is generated by `mypy-boto3-builder` 8.12.0. These stubs enhance developer experience by enabling static type checking, autocompletion, and improved readability for `boto3` interactions with DynamoDB, compatible with tools like VSCode, PyCharm, mypy, and pyright. The library is actively maintained with frequent updates to align with new `boto3` versions and Python features.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to obtain type-hinted DynamoDB clients, service resources, and table resources using `types-boto3-dynamodb`. It leverages `typing.TYPE_CHECKING` to ensure the type stubs are only used during static analysis, preventing runtime dependencies in production. The `boto3` library must be installed alongside these type stubs for full functionality.

import boto3
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from types_boto3_dynamodb import DynamoDBClient, DynamoDBServiceResource
    from types_boto3_dynamodb.service_resource import Table


def get_dynamodb_client() -> 'DynamoDBClient':
    """Returns a type-hinted DynamoDB client."""
    return boto3.client('dynamodb')


def get_dynamodb_resource() -> 'DynamoDBServiceResource':
    """Returns a type-hinted DynamoDB service resource."""
    return boto3.resource('dynamodb')


def get_table(table_name: str) -> 'Table':
    """Returns a type-hinted DynamoDB Table resource."""
    dynamodb_resource: DynamoDBServiceResource = get_dynamodb_resource()
    return dynamodb_resource.Table(table_name)

# Example usage (without actual AWS calls):
client = get_dynamodb_client()
print(f"DynamoDB client type: {type(client)}")

resource = get_dynamodb_resource()
print(f"DynamoDB resource type: {type(resource)}")

# You would typically interact with a real table here
# table = get_table("YourTableName")
# print(f"DynamoDB table type: {type(table)}")

view raw JSON →