PyThenA - Simple Athena Wrapper
raw JSON → 1.6.0 verified Mon Apr 27 auth: no python
A simple Amazon Athena wrapper leveraging boto3 to execute queries and return results. Requires only a database and query string. Current version 1.6.0, last updated 2021-06-28, no recent releases.
pip install pythena Common errors
error ImportError: cannot import name 'PyThenA' from 'pythena' ↓
cause Misspelling or using wrong case.
fix
Use exact case: from pythena import PyThenA
error botocore.errorfactory.InvalidRequestException: An error occurred (InvalidRequestException) when calling the StartQueryExecution operation: Query timeout ↓
cause Query takes longer than default timeout (300 seconds).
fix
Set max_results or use the asynchronous execute_and_wait method with custom timeout.
Warnings
gotcha The execute() method returns a Result object with .data (list of dicts) and .columns (list of column names). Do not expect raw dicts directly. ↓
fix Access result.data for query results.
deprecated The library has not been updated since 2021. boto3 API changes may cause incompatibility with newer AWS API versions. ↓
fix Consider using boto3 directly or awswrangler for Athena queries.
gotcha The PyThenA constructor defaults to 'default' output location 's3://aws-athena-query-results-{account_id}-{region}/'. If your bucket has a different pattern, set output_location explicitly. ↓
fix client = PyThenA(database='mydb', output_location='s3://my-bucket/path/')
Imports
- PyThenA
from pythena import PyThenA
Quickstart
from pythena import PyThenA
import os
database = os.environ.get('ATHENA_DATABASE', 'default')
query = "SELECT 1 AS test"
client = PyThenA(database=database)
result = client.execute(query)
print(result.data)