mypy-boto3-sdb: Type Stubs for boto3 SimpleDB

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-sdb` to add type hints to a `boto3` SimpleDB client. It shows importing `SimpleDBClient` for the client type and `SelectRequestRequestTypeDef` for request parameters, ensuring type safety for `boto3` calls. Remember that `boto3` must be installed and configured separately for runtime execution.

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)

view raw JSON →