Python + REST Track
import json
import requests
API_BASE = "http://api.localhost"
HEADERS = {"Authorization": "Bearer YOUR_LICENSE_KEY"}
db = {
"system": "mysql",
"connection": {
"host": "db.example.com",
"port": 3306,
"database": "analytics",
"user": "app_user",
"password": "secret"
}
}
with open("1000_movie_reviews.csv", "rb") as f:
files = {"file": ("1000_movie_reviews.csv", f, "text/csv")}
data = {"db_config": json.dumps(db)}
upload = requests.post(f"{API_BASE}/upload", headers=HEADERS, files=files, data=data, timeout=120)
upload.raise_for_status()
table = upload.json()["table_name"]
payload = {
"db": db,
"sql": f"SELECT text, tag FROM {table} WHERE AIFILTER(text, 'reviews with positive sentiment') LIMIT 20",
"format": "json"
}
response = requests.post(f"{API_BASE}/query", headers=HEADERS, json=payload, timeout=300)
response.raise_for_status()
print(response.json())