Type Annotations for boto3 DocDB

1.42.3 · active · verified Sat Apr 11

This library provides type annotations for the AWS DocDB (DocumentDB) service client when using boto3. Generated with mypy-boto3-builder 8.12.0, `mypy-boto3-docdb` (current version 1.42.3) enhances static analysis, provides auto-completion in IDEs, and helps catch type-related errors before runtime. It releases in sync with boto3 versions.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `mypy-boto3-docdb` for type hinting a `boto3` DocDB client. It explicitly imports `DocDBClient` and `DescribeDBInstancesResponseTypeDef` under a `TYPE_CHECKING` guard, ensuring they are only used during static analysis and do not add runtime dependencies. The `boto3.client('docdb')` call is type-hinted, enabling autocompletion and type validation for DocDB-specific methods and their responses.

from typing import TYPE_CHECKING
import boto3

if TYPE_CHECKING:
    from mypy_boto3_docdb.client import DocDBClient
    from mypy_boto3_docdb.type_defs import DescribeDBInstancesResponseTypeDef


def get_docdb_instances() -> "DescribeDBInstancesResponseTypeDef":
    # The type hint 'DocDBClient' is picked up by mypy and IDEs.
    # At runtime, you still get the regular boto3 client.
    client: DocDBClient = boto3.client("docdb")
    response = client.describe_db_instances()
    print(f"Found {len(response['DBInstances'])} DocDB instances.")
    return response

if __name__ == "__main__":
    # This example requires AWS credentials configured (e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
    # or ~/.aws/credentials) to run successfully against a real AWS account.
    try:
        instances_data = get_docdb_instances()
        # Further processing with type-checked 'instances_data'
    except Exception as e:
        print(f"Error describing DocDB instances: {e}")

view raw JSON →