Python API Reference
Complete reference for the AVA Python API (avapy module).
Installation
# Install from PyPI
pip install avapy
# Or install from source
cd api/python
python setup.py install
# Verify installation
python -c "import avapy; avapy.version()"
Core Functions
avapy.asql(query)
Execute an AVA SQL query and return results.
Parameters
query(str) - SQL query string to execute
Returns
Query results as a table object
Example
import avapy
# Execute query
result = avapy.asql("""
SELECT product, SUM(sales) as total
FROM sales_data
GROUP BY product
ORDER BY total DESC
""")
print(result)
avapy.LoadTable(filepath, tablename)
Load data from a CSV file into AVA.
Parameters
filepath(str) - Path to CSV filetablename(str) - Name for the table in AVA
Example
# Load CSV file
avapy.LoadTable("sales.csv", "sales_data")
# Verify loaded
tables = avapy.ListTables()
print(tables)
avapy.ListTables()
List all tables currently loaded in AVA.
Returns
List of table names
Example
tables = avapy.ListTables()
for table in tables:
print(f"Table: {table}")
Table Operations
avapy.GetTable(tablename)
Get a reference to a table object.
Parameters
tablename(str) - Name of the table
Returns
Table object
Example
table = avapy.GetTable("sales_data")
print(f"Table has {table.count()} rows")
# Get column names
columns = table.colnames()
print(f"Columns: {columns}")
avapy.Show(table)
Display table contents in formatted output.
Parameters
table(Table) - Table object to display
Example
table = avapy.GetTable("sales_data")
avapy.Show(table)
Data Conversion
Convert AVA columns to Python/NumPy data types.
avapy.ColToNumpy(column)
Convert an AVA column to NumPy array.
Parameters
column(Column) - AVA column object
Returns
NumPy ndarray
Example
import numpy as np
table = avapy.GetTable("sales_data")
col = table.column("revenue")
# Convert to NumPy
arr = avapy.ColToNumpy(col)
print(f"Mean: {np.mean(arr)}")
print(f"Std: {np.std(arr)}")
Other Conversion Functions
- avapy.ColToDouble(column) → list[float]
- avapy.ColToInt(column) → list[int]
- avapy.ColToString(column) → list[str]
- avapy.ColToDate(column) → list[date]
- avapy.ColToBool(column) → list[bool]
Data Types
AVA supports the following data types via the avapy.dtype enum:
DOUBLE
64-bit float
FLOAT
32-bit float
INT
32-bit integer
LONG
64-bit integer
VARCHAR
Variable string
DATE
Date type
TIME
Time type
BOOL
Boolean
Complete Example
import avapy
import numpy as np
# Load data
avapy.LoadTable("sales.csv", "sales")
avapy.LoadTable("customers.csv", "customers")
# List tables
print("Loaded tables:", avapy.ListTables())
# Run analysis query
result = avapy.asql("""
SELECT
c.segment,
COUNT(*) as num_customers,
SUM(s.revenue) as total_revenue,
AVG(s.revenue) as avg_revenue
FROM sales s
JOIN customers c ON s.customer_id = c.id
GROUP BY c.segment
ORDER BY total_revenue DESC
""")
print("Sales by Segment:")
avapy.Show(result)
# Get table object
sales = avapy.GetTable("sales")
print(f"Sales table has {sales.count()} rows")
# Convert to NumPy for analysis
revenue_col = sales.column("revenue")
revenue_arr = avapy.ColToNumpy(revenue_col)
print(f"Revenue Stats:")
print(f" Mean: ${np.mean(revenue_arr):,.2f}")
print(f" Median: ${np.median(revenue_arr):,.2f}")
print(f" Std Dev: ${np.std(revenue_arr):,.2f}")
# Create regression model
avapy.asql("""
CREATE REGRESSION MODEL revenue_model
AS SELECT price, quantity, discount
FROM sales
PREDICT revenue
""")
print("Model created successfully!")