mypy-boto3-athena Type Stubs

1.42.43 · active · verified Thu Apr 09

mypy-boto3-athena provides PEP 561 compliant type annotations (stubs) for the boto3 Athena service. It allows static type checkers like MyPy to validate usage of boto3's Athena client, improving code quality and catching errors early. The package is generated by mypy-boto3-builder, and its releases are frequent, typically mirroring boto3 updates and builder enhancements. Current version is 1.42.43.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize an Athena client with type annotations from `mypy-boto3-athena` and define input parameters using TypeDefs, enabling static type checking for your boto3 calls. It assumes `boto3` is already installed and configured with AWS credentials.

import boto3
from mypy_boto3_athena.client import AthenaClient
from mypy_boto3_athena.type_defs import StartQueryExecutionInputRequestTypeDef
import os

# Instantiate a boto3 Athena client with type annotations
def get_athena_client() -> AthenaClient:
    return boto3.client("athena", region_name=os.environ.get('AWS_REGION', 'us-east-1'))

client: AthenaClient = get_athena_client()

# Define input using a TypeDef for static checking
query_execution_input: StartQueryExecutionInputRequestTypeDef = {
    "QueryString": "SELECT 1 FROM \"AwsDataCatalog\".\"default\".\"test_table\" LIMIT 1;",
    "WorkGroup": os.environ.get('ATHENA_WORKGROUP', 'primary'),
    "ResultConfiguration": {
        "OutputLocation": os.environ.get('ATHENA_OUTPUT_LOCATION', 's3://your-athena-results-bucket/'),
    },
}

print(f"Client type: {type(client)}")
print("Type checking for Athena operations is now enabled.")

# Example of a type-checked call (uncomment to run, requires valid AWS setup)
# try:
#     response = client.start_query_execution(**query_execution_input)
#     print(f"Query Execution ID: {response['QueryExecutionId']}")
# except Exception as e:
#     print(f"Error starting query (ensure AWS_REGION, ATHENA_WORKGROUP, ATHENA_OUTPUT_LOCATION are set and valid): {e}")

view raw JSON →