mypy-boto3-kendra-ranking Type Stubs

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This example demonstrates how to type-hint a `boto3` KendraRanking client and use a typical operation, `list_tags_for_resource`. Run `mypy <your_script_name>.py` to verify type correctness.

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.")

view raw JSON →