SQL Querying with Python
Python developers can run SQL queries programmatically to search the ChaosSearch indexed data.
Python developers can create applications to run a SQL search of the ChaosSearch indexed data. The following example shows a simple SELECT operation for sample view. Make sure that you gather information like the ChaosSearch domain name that you plan to access, the Refinery view that you will be searching, and your account's API access key and secret key for authenticating your user access to ChaosSearch.
For the ChaosSearch indexed data, be sure to use a Trino connection type, and be sure to familiarize yourself with the SQL Syntax Support for the environment including the latest list of Unsupported SQL Syntax.
Note that the SQL API currently supports only read/SELECT operations against the ChaosSearch indexed data.
import time
import trino
conn = trino.dbapi.connect(
host='<REPLACE-WITH_CHAOSSEARCH-HOST>',
port=443,
user="<REPLACE_WITH_ACCESS_KEY>",
schema='chaos',
http_scheme='https',
auth=trino.auth.BasicAuthentication("<REPLACE_WITH_ACCESS_KEY>","<REPLACE_WITH_SECRET_KEY>")
)
cur = conn.cursor()
cur = conn.cursor()
cur.execute("SELECT * FROM <REPLACE-VIEW-NAME>")
rows = cur.fetchall()
for row in rows:
print(row)
Updated about 1 year ago