Skip to content

Examples#

Index > DynamoDB > Examples

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

Client#

Implicit type annotations#

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

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

# DynamoDBClient usage example

from boto3.session import Session


session = Session()

client = session.client("dynamodb")  # (1)
result = client.batch_execute_statement()  # (2)
  1. client: DynamoDBClient
  2. result: BatchExecuteStatementOutputTypeDef
# ListBackupsPaginator usage example

from boto3.session import Session


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

paginator = client.get_paginator("list_backups")  # (2)
for item in paginator.paginate(...):
    print(item)  # (3)
  1. client: DynamoDBClient
  2. paginator: ListBackupsPaginator
  3. item: ListBackupsOutputTypeDef
# TableExistsWaiter usage example

from boto3.session import Session


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

waiter = client.get_waiter("table_exists")  # (2)
waiter.wait()
  1. client: DynamoDBClient
  2. waiter: TableExistsWaiter

Explicit type annotations#

With types-boto3-lite[dynamodb] or a standalone types_boto3_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.

# DynamoDBClient usage example with type annotations

from boto3.session import Session

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


session = Session()

client: DynamoDBClient = session.client("dynamodb")

kwargs: BatchExecuteStatementInputRequestTypeDef = {...}
result: BatchExecuteStatementOutputTypeDef = client.batch_execute_statement(**kwargs)
# ListBackupsPaginator usage example with type annotations

from boto3.session import Session

from types_boto3_dynamodb.client import DynamoDBClient
from types_boto3_dynamodb.paginator import ListBackupsPaginator
from types_boto3_dynamodb.type_defs import ListBackupsOutputTypeDef


session = Session()
client: DynamoDBClient = session.client("dynamodb")

paginator: ListBackupsPaginator = client.get_paginator("list_backups")
for item in paginator.paginate(...):
    item: ListBackupsOutputTypeDef
    print(item)
# TableExistsWaiter usage example with type annotations

from boto3.session import Session

from types_boto3_dynamodb.client import DynamoDBClient
from types_boto3_dynamodb.waiter import TableExistsWaiter

session = Session()
client: DynamoDBClient = session.client("dynamodb")

waiter: TableExistsWaiter = client.get_waiter("table_exists")
waiter.wait()

Service Resource#

Implicit type annotations#

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

# DynamoDBServiceResource usage example

from boto3.session import Session


session = Session()

resource = session.resource("dynamodb")  # (1)
result = resource.get_available_subresources()  # (2)
  1. resource: DynamoDBServiceResource
  2. result:
# ServiceResourceTablesCollection usage example

from boto3.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-boto3-lite[dynamodb] or a standalone types_boto3_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.

# DynamoDBServiceResource usage example with type annotations

from boto3.session import Session

from types_boto3_dynamodb.service_resource import DynamoDBServiceResource
from types_boto3_dynamodb.service_resource import get_available_subresources


session = Session()

resource: DynamoDBServiceResource = session.resource("dynamodb")
result: get_available_subresources = resource.get_available_subresources()
# ServiceResourceTablesCollection usage example with type annotations

from boto3.session import Session

from types_boto3_dynamodb.service_resource import DynamoDBServiceResource
from types_boto3_dynamodb.service_resource import ServiceResourceTablesCollection
from types_boto3_dynamodb.service_resource import Table


session = Session()

resource: DynamoDBServiceResource = session.resource("dynamodb")

collection: ServiceResourceTablesCollection = resource.tables
for item in collection:
    item: Table
    print(item)