{"id":1570,"library":"mypy-boto3-dynamodb","title":"mypy-boto3-dynamodb Type Annotations","description":"mypy-boto3-dynamodb provides type annotations for the `boto3` DynamoDB service client and resource, generated by `mypy-boto3-builder`. It ensures type-checking accuracy for your boto3 calls related to DynamoDB. The current version is 1.42.73 and it releases frequently, often in lockstep with boto3/botocore updates.","status":"active","version":"1.42.73","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["boto3","dynamodb","mypy","type-hints","stubs","aws"],"install":[{"cmd":"pip install mypy-boto3-dynamodb","lang":"bash","label":"Install specific DynamoDB stubs"},{"cmd":"pip install mypy-boto3[dynamodb]","lang":"bash","label":"Install with meta-package (requires mypy-boto3)"}],"dependencies":[{"reason":"Provides the runtime objects for which these stubs provide types.","package":"boto3","optional":false}],"imports":[{"symbol":"DynamoDBClient","correct":"from mypy_boto3_dynamodb.client import DynamoDBClient"},{"symbol":"DynamoDBServiceResource","correct":"from mypy_boto3_dynamodb.service_resource import DynamoDBServiceResource"},{"note":"Type definitions for service request/response objects are in `type_defs`.","symbol":"CreateTableInputRequestTypeDef","correct":"from mypy_boto3_dynamodb.type_defs import CreateTableInputRequestTypeDef"}],"quickstart":{"code":"import boto3\nfrom mypy_boto3_dynamodb.client import DynamoDBClient\nfrom mypy_boto3_dynamodb.type_defs import CreateTableInputRequestTypeDef\n\ndef create_table_example(table_name: str, region: str = 'us-east-1'):\n    client: DynamoDBClient = boto3.client('dynamodb', region_name=region)\n\n    table_params: CreateTableInputRequestTypeDef = {\n        'TableName': table_name,\n        'KeySchema': [\n            {'AttributeName': 'id', 'KeyType': 'HASH'}\n        ],\n        'AttributeDefinitions': [\n            {'AttributeName': 'id', 'AttributeType': 'S'}\n        ],\n        'BillingMode': 'PAY_PER_REQUEST'\n    }\n\n    print(f\"Attempting to create table {table_name}...\")\n    try:\n        response = client.create_table(**table_params)\n        print(f\"Table creation initiated: {response['TableDescription']['TableArn']}\")\n    except client.exceptions.ResourceInUseException:\n        print(f\"Table {table_name} already exists.\")\n    except Exception as e:\n        print(f\"Error creating table: {e}\")\n\nif __name__ == '__main__':\n    # This example requires valid AWS credentials configured (e.g., via AWS CLI or environment variables)\n    # It's intended for demonstration; actual resource creation might incur costs.\n    # Create a dummy table name for testing.\n    test_table_name = 'MyTestTableForMypyBoto3'\n    create_table_example(test_table_name)\n    # Note: In a real scenario, you'd likely wait for the table to become active\n    # and then delete it after testing to avoid accumulating resources.","lang":"python","description":"This quickstart demonstrates how to use `mypy-boto3-dynamodb` to type-hint a `boto3` DynamoDB client and a `CreateTableInputRequestTypeDef` for creating a table. The types provide autocompletion and static analysis for your DynamoDB operations."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or newer.","message":"Starting with version 8.12.0, mypy-boto3-builder (and thus mypy-boto3-dynamodb) removed support for Python 3.8. Ensure your project is running on Python 3.9 or higher.","severity":"breaking","affected_versions":">=8.12.0"},{"fix":"Refer to the official documentation or the `mypy-boto3` changelog for specific service updates. Update your TypeDef imports and usages accordingly.","message":"Type definition (TypeDef) names for request/response objects can change between major versions or updates to reflect AWS API changes or internal renaming conventions. For example, `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef` in version 8.9.0 (for CloudFront). This can break type hints in your code.","severity":"gotcha","affected_versions":">=8.9.0"},{"fix":"Check the `mypy-boto3` changelog or AWS service documentation if your service-specific stub import fails or appears deprecated. Update to the correct service name and import path.","message":"AWS service names can be deprecated or renamed, leading to stubs for old service names being removed or requiring migration to new ones. For instance, `sms-voice` stubs were removed in favor of `pinpoint-sms-voice` in version 8.11.0.","severity":"gotcha","affected_versions":">=8.11.0"},{"fix":"Use `pip install mypy-boto3-myservice` for each specific service you need. Alternatively, use `pip install 'mypy-boto3[myservice]'` to explicitly pull in specific service stubs via the meta-package without installing all.","message":"If you only need stubs for a specific AWS service like DynamoDB, install `mypy-boto3-dynamodb`. Installing the main `mypy-boto3` meta-package will install stubs for *all* AWS services, which might lead to a larger dependency footprint and potentially slower type-checking for large projects.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}