mypy-boto3-kendra
mypy-boto3-kendra provides static type annotations for the `boto3` AWS Kendra service client, enabling tools like MyPy to perform comprehensive static analysis on code interacting with AWS Kendra. It is a generated stub package, part of the larger `mypy-boto3` project which produces type stubs for all `boto3` services. The library is actively maintained and frequently updated, usually in sync with new `boto3` and `botocore` releases, currently at version 1.42.3.
Warnings
- breaking Python 3.8 is no longer supported. `mypy-boto3-builder` version 8.12.0 and subsequent versions (which generate `mypy-boto3-kendra` 1.42.3) removed Python 3.8 support.
- breaking TypeDefs for packed method arguments now use shorter names, and conflicting TypeDef `Extra` postfixes have moved. This is a breaking change for code that explicitly references generated `TypeDef` classes by their full names.
- gotcha The `mypy-boto3-kendra` package provides only type stubs. You still need `boto3` installed at runtime to execute your code. This package enables type checking for `boto3` calls, not the `boto3` functionality itself.
- gotcha Since `mypy-boto3` migrated to PEP 561, the generated packages are now proper stub packages. While generally an improvement, if you had a complex custom setup around older non-PEP 561 compliant versions or were relying on specific internal structures, it might require minor adjustments to your build or type-checking configuration.
Install
-
pip install mypy-boto3-kendra boto3
Imports
- KendraClient
from mypy_boto3_kendra.client import KendraClient
- ListIndicesOutputTypeDef
from mypy_boto3_kendra.type_defs import ListIndicesOutputTypeDef
- KendraServiceName
from mypy_boto3_kendra import KendraServiceName
Quickstart
import boto3
from mypy_boto3_kendra.client import KendraClient
from mypy_boto3_kendra.type_defs import IndexConfigurationSummaryTypeDef, ListIndicesOutputTypeDef
from typing import List
import os
def list_kendra_indices() -> List[IndexConfigurationSummaryTypeDef]:
"""Lists Kendra indices and returns their summaries."""
# Ensure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
# For explicit credential provision (if not using implicit chain):
# client: KendraClient = boto3.client(
# "kendra",
# aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', ''),
# aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', ''),
# region_name=os.environ.get('AWS_REGION', 'us-east-1')
# )
client: KendraClient = boto3.client("kendra")
# Using type hints for the response
response: ListIndicesOutputTypeDef = client.list_indices()
indices: List[IndexConfigurationSummaryTypeDef] = response.get('IndexConfigurationSummaryItems', [])
if indices:
print(f"Found Kendra indices: {[i['Name'] for i in indices]}")
else:
print("No Kendra indices found.")
return indices
if __name__ == "__main__":
list_kendra_indices()