types-aiobotocore-dynamodb Type Stubs
This library provides type annotations (stubs) for `aiobotocore`'s DynamoDB service, enhancing static analysis tools like MyPy and IDE autocompletion for asynchronous AWS interactions. Currently at version 3.4.0, it is actively maintained with frequent updates tied to `aiobotocore` and `mypy-boto3-builder` releases.
Warnings
- breaking Python 3.8 support has been removed in `mypy-boto3-builder` version 8.12.0, which generates these type stubs. Users on Python 3.8 or older will need to upgrade to Python 3.9+ to use the latest versions of these stubs.
- breaking The underlying `mypy-boto3-builder` (version 8.12.0) migrated to PEP 561 compliant packages. This change might affect how type checkers or development environments discover and resolve type stubs, particularly in complex project setups.
- breaking Starting with `mypy-boto3-builder` 8.9.0, some TypeDef names may have been shortened or altered (e.g., `CreateDistributionRequestRequestTypeDef` to `CreateDistributionRequestTypeDef`) or conflicting postfixes moved for consistency. This could break explicit references to these TypedDicts in your code.
- gotcha The `types-aiobotocore` ecosystem generates separate packages for each AWS service (e.g., `types-aiobotocore-dynamodb`). Installing only `types-aiobotocore` (without service extras or the `full` extra) will not provide type hints for individual services like DynamoDB.
- gotcha While many IDEs and static analyzers can infer types implicitly, for `types-aiobotocore-lite` or standalone service packages, explicit type annotations (e.g., `client: DynamoDBClient`) might be required or provide clearer hints for optimal type checking and autocompletion.
- gotcha PyCharm users might experience slow performance with `Literal` overloads provided by these stubs (due to PyCharm issue PY-40997). The documentation recommends using `types-aiobotocore-lite` or disabling PyCharm's internal type checker in favor of external tools like MyPy or Pyright.
Install
-
pip install types-aiobotocore-dynamodb -
pip install 'types-aiobotocore[dynamodb]'
Imports
- DynamoDBClient
from types_aiobotocore_dynamodb.client import DynamoDBClient
- DynamoDBServiceResource
from types_aiobotocore_dynamodb.service_resource import DynamoDBServiceResource
Quickstart
import asyncio
import os
from aiobotocore.session import get_session
from types_aiobotocore_dynamodb.client import DynamoDBClient
async def list_dynamodb_tables():
# aiobotocore automatically picks up credentials from environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION)
# or ~/.aws/credentials and ~/.aws/config
session = get_session()
async with session.create_client("dynamodb", region_name=os.environ.get('AWS_REGION', 'us-east-1')) as client:
client: DynamoDBClient # Explicit type hint for static analysis
print(f"Listing DynamoDB tables in {client.meta.region_name}...")
response = await client.list_tables()
tables = response.get("TableNames", [])
if tables:
print("Found tables:", ", ".join(tables))
else:
print("No tables found.")
if __name__ == "__main__":
# Ensure AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_REGION are set in your environment
# For a runnable example, you might need valid AWS credentials configured.
# Example placeholder: os.environ['AWS_REGION'] = 'us-east-1'
asyncio.run(list_dynamodb_tables())