Type Annotations for boto3 QConnect
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
- breaking Python 3.8 is no longer supported. Packages built with `mypy-boto3-builder` version 8.12.0 and higher (including `mypy-boto3-qconnect 1.42.84`) require Python 3.9 or newer.
- gotcha This package provides only type stubs. You must install `boto3` separately for actual runtime functionality. Forgetting `boto3` will lead to `ModuleNotFoundError` or similar runtime issues.
- breaking Some `TypedDict` argument names (e.g., `CreateDistributionRequestRequestTypeDef`) were shortened or renamed to avoid redundancy in `mypy-boto3-builder` 8.9.0. While `qconnect` specifically fixed self-references in 8.11.0, other services saw general renaming. Review your code for `*RequestRequestTypeDef` patterns.
- gotcha Previous versions of `mypy-boto3-qconnect` (built with `mypy-boto3-builder` prior to 8.11.0) had issues with self-references in `TypedDict`s which could lead to incorrect type checking or errors. This was specifically fixed for `qconnect`.
- gotcha The `mypy-boto3-builder` migrated to PEP 561-compliant packages in version 8.12.0. This change ensures better compatibility with `mypy` and other type checkers but might require `mypy` to be updated or reconfigured in some complex setups if type resolution issues arise.
Install
-
pip install mypy-boto3-qconnect boto3
Imports
- QConnectClient
from mypy_boto3_qconnect.client import QConnectClient
- QueryKnowledgeBaseResponseTypeDef
from mypy_boto3_qconnect.type_defs import QueryKnowledgeBaseResponseTypeDef
- QConnectServiceName
from mypy_boto3_qconnect.literals import QConnectServiceName
Quickstart
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.")