mypy-boto3-athena Type Stubs
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
- breaking Python 3.8 support has been removed since `mypy-boto3-builder` version 8.12.0. All `mypy-boto3` packages built with this builder or later will require Python 3.9 or higher.
- breaking Migration to PEP 561 packages in `mypy-boto3-builder` version 8.12.0 changes the internal structure and how type checkers locate stubs. While user-facing imports are generally stable, some tooling or custom MyPy configurations might require adjustments.
- gotcha This package provides only type stubs, not the functional `boto3` library itself. You must explicitly install `boto3` (e.g., `pip install boto3`) for your code to run.
- breaking In `mypy-boto3-builder` version 8.9.0, TypeDef naming conventions were updated. This included shortening duplicated 'Request' suffixes (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`) and moving 'Extra' postfixes. If you directly imported specific TypeDefs, their names might have changed.
Install
-
pip install mypy-boto3-athena -
pip install boto3
Imports
- AthenaClient
from mypy_boto3_athena.client import AthenaClient
- StartQueryExecutionInputRequestTypeDef
from mypy_boto3_athena.type_defs import StartQueryExecutionInputRequestTypeDef
Quickstart
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}")