Skip to content

Instantly share code, notes, and snippets.

@ruslanmv
Created December 25, 2021 10:19
Show Gist options
  • Save ruslanmv/14b10dabce4bc129ade868e8ddab967a to your computer and use it in GitHub Desktop.
Save ruslanmv/14b10dabce4bc129ade868e8ddab967a to your computer and use it in GitHub Desktop.
Connecting Python with Athena via pyathena
import pyathena
import pandas as pd
## Directly by panda
athena_conn = pyathena.connect(aws_access_key_id=os.environ['ATHENA_USER'], ##credentials of aws_access_key_id
aws_secret_access_key=os.environ['ATHENA_PASSWORD'], ##credentials of aws_secret_access_key
s3_staging_dir='s3://aws-athena-query-results-<your-details>', ##where the athena query result saved - checked in S3 ,
region_name='eu-west-1') ##the region you set for Athena
df = pd.read_sql("SELECT * FROM tutorial.wbcdata LIMIT 10", athena_conn)
df.head(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment