Skip to main content

Installation

pip install ajna-analytical-engine

1. Create Your Datasource Configuration

The engine requires a datasource configuration file. Create my_datasources.yaml:
# Database connections
sources:
  users_table:
    type: postgres
    host: localhost
    port: 5432
    database: mydb
    username: myuser
    password: mypassword
    
  products_table:
    type: mysql
    host: localhost
    port: 3306
    database: analytics
    username: root
    password: secret

# Table schemas
tables:
  users_table:
    columns:
      id: {type: integer, primary_key: true}
      name: {type: string}
      email: {type: string}
      created_at: {type: timestamp}
      
  products_table:
    columns:
      id: {type: integer, primary_key: true}
      name: {type: string}
      price: {type: float}
      category: {type: string}

2. Initialize and Query

from pathlib import Path
from ajna_analytical_engine import AnalyticalEngine, QueryRequest

# Initialize with your datasource config
engine = AnalyticalEngine(
    datasource_config_path=Path("my_datasources.yaml")
)

# Query users
query = QueryRequest(
    sources=["users_table"],
    select=["name", "email"],
    filters={"users_table": [{"column": "name", "op": "like", "value": "%john%"}]},
    limit=10
)

result = engine.execute_query(query)
print(f"Found {result.metadata.row_count} users")
print(result.data.head())

3. Advanced Queries

# Join query with aggregation
join_query = QueryRequest(
    sources=["users_table", "products_table"],
    joins=[{
        "left": "users_table.id", 
        "right": "products_table.created_by",
        "type": "inner"
    }],
    aggregations=[{
        "function": "avg",
        "column": "products_table.price",
        "alias": "avg_price"
    }],
    group_by=["users_table.name"]
)

result = engine.execute_query(join_query)

4. Convert SQL to Native Query

from ajna_analytical_engine import SQLToQueryRequest

# Convert existing SQL
sql_request = SQLToQueryRequest(
    sql="SELECT name, COUNT(*) as total FROM users_table GROUP BY name",
    sql_name="user_counts"
)

query_json = engine.convert_sql_to_query(sql_request)
print("Native query JSON:", query_json)

Supported Databases

Production Ready:
  • PostgreSQL
  • MySQL
🔧 Enterprise (via Connection API):
  • AWS Athena
  • Google BigQuery
  • Snowflake
  • Azure Synapse
  • Amazon Redshift
  • SQLite

Quick Configuration Examples

Environment Variables in Connection Strings

sources:
  prod_db:
    type: postgres
    uri: postgresql://${DB_USER}:${DB_PASS}@${DB_HOST}:${DB_PORT}/${DB_NAME}

AWS Athena with IAM

sources:
  athena_data:
    type: athena
    region: us-east-1
    role_arn: arn:aws:iam::123456789:role/AthenaRole
    s3_staging_dir: s3://my-bucket/staging/
    database: my_database

Connection ID (Enterprise)

sources:
  enterprise_db:
    connection_id: "prod-analytics-cluster"

Next Steps: