Skip to content

Examples

Index > DynamoDB > Examples

Auto-generated documentation for DynamoDB type annotations stubs module types-aiobotocore-dynamodb.

Client

Implicit type annotations

Can be used with types-aioboto3[dynamodb] package installed.

Write your DynamoDB code as usual, type checking and code completion should work out of the box.

Client usage example
from aioboto3.session import Session


session = Session()

async with session.client("dynamodb") as client:  # (1)
    result = await client.batch_execute_statement()  # (2)
  1. client: DynamoDBClient
  2. result: BatchExecuteStatementOutputTypeDef
Paginator usage example
from aioboto3.session import Session


session = Session()

async with session.client("dynamodb") as client:  # (1)
    paginator = client.get_paginator("list_backups")  # (2)
    async for item in paginator.paginate(...):
        print(item)  # (3)
  1. client: DynamoDBClient
  2. paginator: ListBackupsPaginator
  3. item: ListBackupsOutputTableTypeDef
Waiter usage example
from aioboto3.session import Session


session = Session()

async with session.client("dynamodb") as client:  # (1)
    waiter = client.get_waiter("table_exists")  # (2)
    await waiter.wait()
  1. client: DynamoDBClient
  2. waiter: TableExistsWaiter

Explicit type annotations

With types-aioboto3-lite[dynamodb] or a standalone types_aiobotocore_dynamodb package, you have to explicitly specify client: DynamoDBClient type annotation.

All other type annotations are optional, as types should be discovered automatically. However, these type annotations can be helpful in your functions and methods.

Client usage example
from aioboto3.session import Session

from types_aiobotocore_dynamodb.client import DynamoDBClient
from types_aiobotocore_dynamodb.type_defs import BatchExecuteStatementOutputTypeDef
from types_aiobotocore_dynamodb.type_defs import BatchExecuteStatementInputRequestTypeDef


session = Session()

client: DynamoDBClient
async with session.client("dynamodb") as client:  # (1)
    kwargs: BatchExecuteStatementInputRequestTypeDef = {...}  # (2)
    result: BatchExecuteStatementOutputTypeDef = await client.batch_execute_statement(**kwargs)  # (3)
  1. client: DynamoDBClient
  2. kwargs: BatchExecuteStatementInputRequestTypeDef
  3. result: BatchExecuteStatementOutputTypeDef
Paginator usage example
from aioboto3.session import Session

from types_aiobotocore_dynamodb.client import DynamoDBClient
from types_aiobotocore_dynamodb.paginator import ListBackupsPaginator
from types_aiobotocore_dynamodb.type_defs import ListBackupsOutputTableTypeDef


session = Session()

client: DynamoDBClient
async with session.client("dynamodb") as client:  # (1)
    paginator: ListBackupsPaginator = client.get_paginator("list_backups")  # (2)
    async for item in paginator.paginate(...):
        item: ListBackupsOutputTableTypeDef
        print(item)  # (3)
  1. client: DynamoDBClient
  2. paginator: ListBackupsPaginator
  3. item: ListBackupsOutputTableTypeDef
Waiter usage example
from aioboto3.session import Session

from types_aiobotocore_dynamodb.client import DynamoDBClient
from types_aiobotocore_dynamodb.waiter import TableExistsWaiter


session = Session()

async with session.client("dynamodb") as client:  # (1)
    waiter = client.get_waiter("table_exists")  # (2)
    await waiter.wait()
  1. client: DynamoDBClient
  2. waiter: TableExistsWaiter

Service Resource

Implicit type annotations

Can be used with types-aioboto3[dynamodb] package installed.

ServiceResource usage example
from aioboto3.session import Session


session = Session()

async with session.resource("dynamodb") as resource:  # (1)
    result = resource.Table()  # (2)
  1. resource: DynamoDBServiceResource
  2. result:
Collection usage example
from aioboto3.session import Session


session = Session()
resource = session.resource("dynamodb")  # (1)

collection = resource.tables  # (2)
for item in collection:
    print(item)  # (3)
  1. resource: DynamoDBServiceResource
  2. collection: DynamoDBServiceResource
  3. item: Table

Explicit type annotations

With types-aioboto3-lite[dynamodb] or a standalone types_aiobotocore_dynamodb package, you have to explicitly specify resource: DynamoDBServiceResource type annotation.

All other type annotations are optional, as types should be discovered automatically. However, these type annotations can be helpful in your functions and methods.

ServiceResource usage example
from aioboto3.session import Session

from types_aiobotocore_dynamodb.service_resource import DynamoDBServiceResource
from types_aiobotocore_dynamodb.service_resource import Table


session = Session()

resource: DynamoDBServiceResource
async with session.resource("dynamodb") as resource:  # (1)
    result: Table = resource.Table() # (2)
  1. resource: DynamoDBServiceResource
  2. result:
Collection usage example
from aioboto3.session import Session

from types_aiobotocore_dynamodb.service_resource import DynamoDBServiceResource
from types_aiobotocore_dynamodb.service_resource import ServiceResourceTablesCollection
from types_aiobotocore_dynamodb.service_resource import Table


session = Session()

resource: DynamoDBServiceResource
async with session.resource("dynamodb") as resource:  # (1)
    collection: ServiceResourceTablesCollection = resource.tables  # (2)
    for item in collection:
        item: Table
        print(item)  # (3)
  1. resource: DynamoDBServiceResource
  2. collection: DynamoDBServiceResource
  3. item: Table