Type Annotations for boto3 QConnect

1.42.84 · active · verified Sat Apr 11

mypy-boto3-qconnect provides comprehensive type annotations for the AWS QConnect service client within `boto3`. It enhances development with static type checking for all QConnect operations, improving code reliability and developer experience. The current version is 1.42.84, and it follows a frequent release cadence, often aligning with `boto3` and AWS service updates, managed by the `mypy-boto3-builder`.

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize a `boto3` QConnect client with `mypy-boto3-qconnect` type hints and perform a basic operation, showcasing how types are applied to both the client and its method responses.

import boto3
from mypy_boto3_qconnect.client import QConnectClient
from mypy_boto3_qconnect.type_defs import QueryKnowledgeBaseResponseTypeDef

# Ensure boto3 is installed and configured (e.g., via AWS CLI or env vars)
# A client without explicit credentials will use default AWS configuration.

# Use type hint for the boto3 client
client: QConnectClient = boto3.client("qconnect")

# Example: List knowledge bases
try:
    # Type checking will ensure correct arguments and return types
    response = client.list_knowledge_bases()
    print("Successfully listed knowledge bases:")
    for kb in response.get("knowledgeBaseSummaries", []):
        print(f"  - {kb['name']} ({kb['knowledgeBaseId']})")

    # Example with a specific operation and its TypedDict return type
    # Note: Replace 'your-knowledge-base-id' and 'your-query' with actual values
    # if you want to run this part.
    # query_response: QueryKnowledgeBaseResponseTypeDef = client.query_knowledge_base(
    #     knowledgeBaseId="your-knowledge-base-id",
    #     queryText="your-query"
    # )
    # print("Query response type checked.")

except Exception as e:
    print(f"An error occurred: {e}")
    print("Ensure your AWS credentials are configured and QConnect has resources.")

view raw JSON →