Skip to main content

Helps simplify the access of databases stored in Amazon Athena by using SQL and pandas DataFrames.

Project description

athena2pd

License: MIT

athena2pd - Amazon Athena to Pandas Dataframe

About

Useful tool to help simplify the access of databases stored in Amazon Athena by using SQL and pandas DataFrames.

The end user simply needs to provide the query and the bucket where the results are stored, then this package will run the query and return a DataFrame with the data in it, ready to be used for whatever is desired.

Installation

Use the package manager pip to install athena2pd.

pip install athena2pd

Usage

Before use, you will need an AWS key pair, and an IAM profile set up to access both Amazon Athena and S3.

Using local .aws/ files is the safest way to connect, rather than providing the keys in the code. See the example files below:

The .aws/credentials file is set up like this:

[default]
aws_access_key_id = {access_key_id}
aws_secret_access_key = {secret_access_key}

...

In addition, the .aws/config is set up similar to this:

[default]
output = json
region = us-east-1

[profile athena-role]
role_arn = arn:aws:iam::{iam-id-number}:role/{role-name}
source_profile = default
region = us-east-1

...

Once that is set up, in your python code, the athena2pd package can be used like so:

from athena2pd import AthenaDFConnector

# Initialize the AthenaDFConnector object
ath = AthenaDFConnector(aws_profile_name='athena-role')

# Example SQL query
sql_query = '''
SELECT COUNT(*) AS Count
FROM testcatalog.testdatabase.testtable
'''

# Example output location
output_loc = 's3://bucket-name/sub/folder'

# Query Athena and load into a pandas DataFrame
df = ath.query(query_string=sql_query, s3_output_location=output_loc)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

athena2pd-0.2.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

athena2pd-0.2.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file athena2pd-0.2.1.tar.gz.

File metadata

  • Download URL: athena2pd-0.2.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2

File hashes

Hashes for athena2pd-0.2.1.tar.gz
Algorithm Hash digest
SHA256 a0f9648428d2089019c34cbd1b76fe6f3203d187b76ffbdd58da556b6043e29e
MD5 0a7894c56bb6ddd1e86a7b7908f2ba5c
BLAKE2b-256 50c414f8e3dc4b4f2830a192b52807a3bfd1a66c9cffc49227551bb60ac8860a

See more details on using hashes here.

File details

Details for the file athena2pd-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: athena2pd-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2

File hashes

Hashes for athena2pd-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 12184a6974f4f1b3c864b2dcbc81ed3e7ecb04fdc9e3d883228f5656676c5477
MD5 09ffbaee8db433274c71638eb76d2339
BLAKE2b-256 74c215e27598e3d96d30ec0f8d2c338ff226dfe2752aacde2a1423c2b48c6cda

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page