llama-index readers athena integration
Project description
Athena reader.
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
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
Built Distribution
File details
Details for the file llama_index_readers_athena-0.3.0.tar.gz
.
File metadata
- Download URL: llama_index_readers_athena-0.3.0.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab3c0df1831e43267ab66a07b5ce214f7b92e83c9ad1cc14527c8d6d83069d91 |
|
MD5 | 0b698ffeca889674560ce7fe6f777704 |
|
BLAKE2b-256 | d91ab4b1d78696fadf7d4d97c7d34d14e41d78f7a7beaf3190b4ae5770db428b |
File details
Details for the file llama_index_readers_athena-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: llama_index_readers_athena-0.3.0-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cec179ecd2449e31109ef677857657573d98b9a001c3bde594653a9c85a397d7 |
|
MD5 | a21bc8e372ff397310e5b6b17526e62b |
|
BLAKE2b-256 | 0b41edc08fa061b830eb39da1d1a62a2a9c0d5ade4b795639ca831fbecaa05b9 |