Skip to main content

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

image

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

llama_index_readers_athena-0.2.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file llama_index_readers_athena-0.2.0.tar.gz.

File metadata

File hashes

Hashes for llama_index_readers_athena-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f65e4ae33978375e88874e7a174f5e11c67be7b3d39b95ff65e60676f45e49f2
MD5 14cbce84f1ba040c930bd1776244d639
BLAKE2b-256 136d5bdd4c48ec97ec6d420c41b33a60a1b2234252d1c18a120fd430db427289

See more details on using hashes here.

File details

Details for the file llama_index_readers_athena-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_readers_athena-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c12a5f0bba97a9ce68fa40c0bd50e3edf004c1f16011ea3a1c33526e3f0ff23
MD5 109aab26a8fc7151bff79ae7e2ebd734
BLAKE2b-256 aaf36fb91ca292f2426fdc2f05f7e10349bf20a1234b47f9889c00b34e957c57

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