mypy-boto3-kendra-ranking Type Stubs
mypy-boto3-kendra-ranking provides comprehensive type annotations for the `boto3` KendraRanking service. It is part of the `mypy-boto3` project, which generates complete type stubs for all AWS services supported by `boto3` and `aioboto3`. This library enhances code quality and maintainability by enabling static type checking of `boto3` usage in Python projects. The current version is `1.42.3`, generated with `mypy-boto3-builder 8.12.0`, and new versions are released frequently to synchronize with `boto3` updates.
Warnings
- breaking Python 3.8 support has been removed in `mypy-boto3-builder` version 8.12.0 and later. Corresponding `mypy-boto3` packages no longer support Python 3.8.
- breaking The `mypy-boto3` project migrated to PEP 561 compliant packages in builder version 8.12.0. While this primarily affects package structure, it can have implications for custom packaging workflows or specific tooling integrations.
- gotcha TypeDef naming conventions changed in `mypy-boto3-builder` version 8.9.0. Some TypeDefs for method arguments were shortened (e.g., `RequestRequestTypeDef` -> `RequestTypeDef`). Users referencing older TypeDef names will encounter type errors.
- gotcha Service names in AWS can sometimes change or be deprecated (e.g., `sms-voice` was replaced by `pinpoint-sms-voice` in builder 8.11.0). Always verify the exact service name used in `boto3.client()` matches the `mypy-boto3-*` package you install.
- gotcha For `mypy` to properly find and utilize these stubs, it must be installed and configured correctly. Forgetting to install `mypy` or running it without proper paths are common issues.
- gotcha Stubs can become outdated if `boto3` is updated to a newer version with API changes that are not yet reflected in the corresponding `mypy-boto3-*` package.
Install
-
pip install boto3 mypy-boto3-kendra-ranking mypy
Imports
- KendraRankingClient
from mypy_boto3_kendra_ranking.client import KendraRankingClient
- ListTagsForResourceResponseTypeDef
from mypy_boto3_kendra_ranking.type_defs import ListTagsForResourceResponseTypeDef
Quickstart
import os
import boto3
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from mypy_boto3_kendra_ranking.client import KendraRankingClient
from mypy_boto3_kendra_ranking.type_defs import ListTagsForResourceResponseTypeDef
def get_kendra_ranking_client() -> "KendraRankingClient":
# In a real application, credentials would be managed securely.
# For quickstart, using default session or explicit credentials from env
return boto3.client("kendra-ranking",
region_name=os.environ.get("AWS_REGION", "us-east-1"),
aws_access_key_id=os.environ.get("AWS_ACCESS_KEY_ID", "TEST_KEY"),
aws_secret_access_key=os.environ.get("AWS_SECRET_ACCESS_KEY", "TEST_SECRET"))
def list_kendra_ranking_resource_tags(resource_arn: str) -> None:
client: KendraRankingClient = get_kendra_ranking_client()
try:
response: ListTagsForResourceResponseTypeDef = client.list_tags_for_resource(
ResourceARN=resource_arn
)
print(f"Tags for {resource_arn}:")
for tag in response.get("Tags", []):
print(f" {tag['Key']}: {tag['Value']}")
except client.exceptions.ResourceNotFoundException:
print(f"Resource with ARN '{resource_arn}' not found.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
# Replace with a valid KendraRanking resource ARN if you want to run it against AWS
# Example: 'arn:aws:kendra-ranking:us-east-1:123456789012:rank-evaluation/example'
# For a quickstart that runs without AWS credentials, a dummy ARN is fine for type checking.
dummy_arn = "arn:aws:kendra-ranking:us-east-1:123456789012:rank-evaluation/dummy-evaluation"
list_kendra_ranking_resource_tags(dummy_arn)
print("\nRun `mypy your_script_name.py` to check types.")