mypy-boto3-sdb: Type Stubs for boto3 SimpleDB
mypy-boto3-sdb provides type annotations (stubs) for the boto3 SimpleDB service. It helps developers write type-checked Python code when interacting with AWS SimpleDB using boto3, improving code quality and catching errors pre-runtime. The current version is 1.42.3, and it is updated frequently in sync with boto3 releases and the broader mypy-boto3-builder project.
Warnings
- breaking Support for Python 3.8 was officially removed in `mypy-boto3-builder` version 8.12.0 (and consequently `mypy-boto3-sdb` versions built with it). Projects requiring Python 3.8 should use older versions of `mypy-boto3-sdb`.
- breaking Version 8.9.0 of `mypy-boto3-builder` introduced significant breaking changes to `TypeDef` naming conventions (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`). This can break existing type hints in your codebase.
- gotcha This package (`mypy-boto3-sdb`) provides *only* type stubs. It does not include the runtime `boto3` library. `boto3` must be installed separately for your code to function at runtime.
- gotcha From `mypy-boto3-builder` version 8.12.0, packages migrated to PEP 561 compliance. While this generally improves type checker discovery, older or custom `mypy` configurations might need adjustment (e.g., `mypy_path`) to correctly locate the stubs.
- gotcha Do not attempt to instantiate client classes (e.g., `SimpleDBClient`) directly from `mypy_boto3_sdb`. These are only type definitions. The actual runtime client must be created using `boto3.client('sdb')`.
Install
-
pip install mypy-boto3-sdb boto3
Imports
- SimpleDBClient
from mypy_boto3_sdb.client import SimpleDBClient
- AttributeTypeDef
from mypy_boto3_sdb.type_defs import AttributeTypeDef
Quickstart
import boto3
from mypy_boto3_sdb.client import SimpleDBClient
from mypy_boto3_sdb.type_defs import SelectRequestRequestTypeDef, AttributeTypeDef
def list_sdb_items(domain_name: str, select_expression: str) -> list[dict[str, str]] | None:
"""Fetches items from SimpleDB using type-hinted boto3 client."""
# A boto3 client is used at runtime, type-hinted by mypy-boto3-sdb
sdb_client: SimpleDBClient = boto3.client("sdb")
try:
request: SelectRequestRequestTypeDef = {
"SelectExpression": select_expression,
"ConsistentRead": True,
}
response = sdb_client.select(**request)
items_data = []
if "Items" in response and response["Items"]:
for item in response["Items"]:
item_dict = {"Name": item["Name"]}
if "Attributes" in item and item["Attributes"]:
for attr in item["Attributes"]:
item_dict[attr["Name"]] = attr["Value"]
items_data.append(item_dict)
return items_data
except Exception as e:
print(f"Error fetching items: {e}")
return None
# Example usage (ensure 'boto3' is configured with AWS credentials)
# results = list_sdb_items("my-domain", "select * from `my-domain`")
# if results:
# for item in results:
# print(item)