# Athena reader.
```bash
pip install llama-index-readers-athena
pip install llama-index-llms-openai
```
Athena reader allow execute SQL with AWS Athena. We using SQLAlchemy and PyAthena under the hood.
## Permissions
WE HIGHLY RECOMMEND USING THIS LOADER WITH AWS EC2 IAM ROLE.
## Usage
Here's an example usage of the AthenaReader.
```
import os
import dotenv
from llama_index.core import SQLDatabase,ServiceContext
from llama_index.core.query_engine import NLSQLTableQueryEngine
from llama_index.llms.openai import OpenAI
from llama_index.readers.athena import AthenaReader
dotenv.load_dotenv()
AWS_REGION = os.environ['AWS_REGION']
S3_STAGING_DIR = os.environ['S3_STAGING_DIR']
DATABASE = os.environ['DATABASE']
WORKGROUP = os.environ['WORKGROUP']
TABLE = os.environ['TABLE']
llm = OpenAI(model="gpt-4",temperature=0, max_tokens=1024)
engine = AthenaReader.create_athena_engine(
aws_region=AWS_REGION,
s3_staging_dir=S3_STAGING_DIR,
database=DATABASE,
workgroup=WORKGROUP
)
service_context = ServiceContext.from_defaults(
llm=llm
)
sql_database = SQLDatabase(engine, include_tables=[TABLE])
query_engine = NLSQLTableQueryEngine(
sql_database=sql_database,
tables=[TABLE],
service_context=service_context
)
query_str = (
"Which blocknumber has the most transactions?"
)
response = query_engine.query(query_str)
```
## Screeshot
![image](https://vultureprime-research-center.s3.ap-southeast-1.amazonaws.com/Screenshot+2566-10-07+at+17.58.45.png)
Raw data
{
"_id": null,
"home_page": null,
"name": "llama-index-readers-athena",
"maintainer": "mattick27",
"docs_url": null,
"requires_python": "<4.0,>=3.8.1",
"maintainer_email": null,
"keywords": "aws athena, datalake, sql",
"author": "Your Name",
"author_email": "you@example.com",
"download_url": "https://files.pythonhosted.org/packages/13/6d/5bdd4c48ec97ec6d420c41b33a60a1b2234252d1c18a120fd430db427289/llama_index_readers_athena-0.2.0.tar.gz",
"platform": null,
"description": "# Athena reader.\n\n```bash\npip install llama-index-readers-athena\n\npip install llama-index-llms-openai\n```\n\nAthena reader allow execute SQL with AWS Athena. We using SQLAlchemy and PyAthena under the hood.\n\n## Permissions\n\nWE HIGHLY RECOMMEND USING THIS LOADER WITH AWS EC2 IAM ROLE.\n\n## Usage\n\nHere's an example usage of the AthenaReader.\n\n```\nimport os\nimport dotenv\nfrom llama_index.core import SQLDatabase,ServiceContext\nfrom llama_index.core.query_engine import NLSQLTableQueryEngine\nfrom llama_index.llms.openai import OpenAI\nfrom llama_index.readers.athena import AthenaReader\n\ndotenv.load_dotenv()\n\nAWS_REGION = os.environ['AWS_REGION']\nS3_STAGING_DIR = os.environ['S3_STAGING_DIR']\nDATABASE = os.environ['DATABASE']\nWORKGROUP = os.environ['WORKGROUP']\nTABLE = os.environ['TABLE']\n\nllm = OpenAI(model=\"gpt-4\",temperature=0, max_tokens=1024)\n\nengine = AthenaReader.create_athena_engine(\n aws_region=AWS_REGION,\n s3_staging_dir=S3_STAGING_DIR,\n database=DATABASE,\n workgroup=WORKGROUP\n)\n\nservice_context = ServiceContext.from_defaults(\n llm=llm\n)\n\nsql_database = SQLDatabase(engine, include_tables=[TABLE])\n\nquery_engine = NLSQLTableQueryEngine(\n sql_database=sql_database,\n tables=[TABLE],\n service_context=service_context\n)\nquery_str = (\n \"Which blocknumber has the most transactions?\"\n)\nresponse = query_engine.query(query_str)\n```\n\n## Screeshot\n\n![image](https://vultureprime-research-center.s3.ap-southeast-1.amazonaws.com/Screenshot+2566-10-07+at+17.58.45.png)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "llama-index readers athena integration",
"version": "0.2.0",
"project_urls": null,
"split_keywords": [
"aws athena",
" datalake",
" sql"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "aaf36fb91ca292f2426fdc2f05f7e10349bf20a1234b47f9889c00b34e957c57",
"md5": "109aab26a8fc7151bff79ae7e2ebd734",
"sha256": "6c12a5f0bba97a9ce68fa40c0bd50e3edf004c1f16011ea3a1c33526e3f0ff23"
},
"downloads": -1,
"filename": "llama_index_readers_athena-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "109aab26a8fc7151bff79ae7e2ebd734",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8.1",
"size": 3129,
"upload_time": "2024-08-22T05:48:47",
"upload_time_iso_8601": "2024-08-22T05:48:47.976151Z",
"url": "https://files.pythonhosted.org/packages/aa/f3/6fb91ca292f2426fdc2f05f7e10349bf20a1234b47f9889c00b34e957c57/llama_index_readers_athena-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "136d5bdd4c48ec97ec6d420c41b33a60a1b2234252d1c18a120fd430db427289",
"md5": "14cbce84f1ba040c930bd1776244d639",
"sha256": "f65e4ae33978375e88874e7a174f5e11c67be7b3d39b95ff65e60676f45e49f2"
},
"downloads": -1,
"filename": "llama_index_readers_athena-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "14cbce84f1ba040c930bd1776244d639",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8.1",
"size": 2937,
"upload_time": "2024-08-22T05:48:49",
"upload_time_iso_8601": "2024-08-22T05:48:49.101971Z",
"url": "https://files.pythonhosted.org/packages/13/6d/5bdd4c48ec97ec6d420c41b33a60a1b2234252d1c18a120fd430db427289/llama_index_readers_athena-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-22 05:48:49",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "llama-index-readers-athena"
}