Examples#
Auto-generated documentation for DynamoDB type annotations stubs module mypy-boto3-dynamodb.
Client#
Implicit type annotations#
Can be used with boto3-stubs[dynamodb]
package installed.
Write your DynamoDB
code as usual,
type checking and code completion should work out of the box.
Client method usage example#
# DynamoDBClient usage example
from boto3.session import Session
session = Session()
client = session.client("dynamodb") # (1)
result = client.batch_execute_statement() # (2)
- client: DynamoDBClient
- result: BatchExecuteStatementOutputTypeDef
Paginator usage example#
# 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)
- client: DynamoDBClient
- paginator: ListBackupsPaginator
- item: ListBackupsOutputTypeDef
Waiter usage example#
# TableExistsWaiter usage example
from boto3.session import Session
session = Session()
client = session.client("dynamodb") # (1)
waiter = client.get_waiter("table_exists") # (2)
waiter.wait(...)
- client: DynamoDBClient
- waiter: TableExistsWaiter
Explicit type annotations#
With boto3-stubs-lite[dynamodb]
or a standalone mypy_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.
Client method usage example#
# DynamoDBClient usage example with type annotations
from boto3.session import Session
from mypy_boto3_dynamodb.client import DynamoDBClient
from mypy_boto3_dynamodb.type_defs import BatchExecuteStatementOutputTypeDef
from mypy_boto3_dynamodb.type_defs import BatchExecuteStatementInputTypeDef
session = Session()
client: DynamoDBClient = session.client("dynamodb")
kwargs: BatchExecuteStatementInputTypeDef = {...}
result: BatchExecuteStatementOutputTypeDef = client.batch_execute_statement(**kwargs)
Paginator usage example#
# ListBackupsPaginator usage example with type annotations
from boto3.session import Session
from mypy_boto3_dynamodb.client import DynamoDBClient
from mypy_boto3_dynamodb.paginator import ListBackupsPaginator
from mypy_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)
Waiter usage example#
# TableExistsWaiter usage example with type annotations
from boto3.session import Session
from mypy_boto3_dynamodb.client import DynamoDBClient
from mypy_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 boto3-stubs[dynamodb]
package installed.
ServiceResource method usage example#
# DynamoDBServiceResource usage example
from boto3.session import Session
session = Session()
resource = session.resource("dynamodb") # (1)
result = resource.create_table(...) # (2)
- resource: DynamoDBServiceResource
- result: Table
Collection usage example#
# 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)
- resource: DynamoDBServiceResource
- collection: ServiceResourceTablesCollection
- item: Table
Explicit type annotations#
With boto3-stubs-lite[dynamodb]
or a standalone mypy_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.
ServiceResource method usage example#
# DynamoDBServiceResource usage example with type annotations
from boto3.session import Session
from mypy_boto3_dynamodb.service_resource import DynamoDBServiceResource
from mypy_boto3_dynamodb.service_resource import Table
from mypy_boto3_dynamodb.type_defs import CreateTableInputServiceResourceCreateTableTypeDef
session = Session()
resource: DynamoDBServiceResource = session.resource("dynamodb")
kwargs: CreateTableInputServiceResourceCreateTableTypeDef = {...} # (2)
result: Table = resource.create_table(**kwargs)
- resource: DynamoDBServiceResource
- kwargs: CreateTableInputServiceResourceCreateTableTypeDef
- result: Table
Collection usage example#
# ServiceResourceTablesCollection usage example with type annotations
from boto3.session import Session
from mypy_boto3_dynamodb.service_resource import DynamoDBServiceResource
from mypy_boto3_dynamodb.service_resource import ServiceResourceTablesCollection
from mypy_boto3_dynamodb.service_resource import Table
session = Session()
resource: DynamoDBServiceResource = session.resource("dynamodb") # (1)
collection: ServiceResourceTablesCollection = resource.tables # (2)
for item in collection:
item: Table
print(item) # (3)
- resource: DynamoDBServiceResource
- collection: DynamoDBServiceResource
- item: Table