Python + REST Track
import json
import requests
API_BASE = "https://www.samtsql.com/api"
API_TOKEN = "YOUR_API_TOKEN" # create one under "API Tokens" in the web app
HEADERS = {"Authorization": f"Bearer {API_TOKEN}"}
db = {
"system": "postgres",
"connection": {
"host": "db.example.com",
"port": 5432,
"database": "analytics",
"user": "app_user",
"password": "secret"
}
}
SCHEMA = "public" # PostgreSQL schema for the uploaded table and result
with open("1000_movie_reviews.csv", "rb") as f:
files = {"file": ("1000_movie_reviews.csv", f, "text/csv")}
data = {"db_config": json.dumps(db), "target_schema": SCHEMA}
upload = requests.post(f"{API_BASE}/upload", headers=HEADERS, files=files, data=data, timeout=120)
upload.raise_for_status()
table = upload.json()["table_name"]
query_payload = {
"db": db,
"sql": f"SELECT text, tag FROM {table} WHERE AIFILTER(text, 'reviews with positive sentiment') LIMIT 20",
"format": "json",
"result_schema": SCHEMA,
}
result = requests.post(f"{API_BASE}/query", headers=HEADERS, json=query_payload, timeout=300)
result.raise_for_status()
print(result.json())