clickzetta-connector is the official Python SDK for Singdata Lakehouse. It follows the PEP-249 specification and provides a SQL call interface compliant with the Python Database API style, supporting queries, writes, bulk inserts, and asynchronous execution.
from clickzetta import connect
conn = connect(
username='your_username',
password='your_password',
service='cn-shanghai-alicloud.api.singdata.com', # Service endpoint
instance='your_instance', # Instance name
workspace='your_workspace', # Workspace name
schema='public', # Default schema
vcluster='DEFAULT' # Compute cluster name
)
Connection parameters
Parameter
Required
Description
username
Yes
Username
password
Yes
Password
service
Yes
Service endpoint, format region_id.api.singdata.com, available in the JDBC connection string under Studio Management → Workspace
instance
Yes
Instance name, same location as above
workspace
Yes
Workspace name
schema
Yes
Default schema name
vcluster
Yes
Compute cluster name, use default as the default
protocol
No
Default https, supports http / https
Execute Queries
cursor = conn.cursor()
Execute a query:
cursor.execute('SELECT * FROM orders LIMIT 10')
Fetch results:
results = cursor.fetchall()
for row in results:
print(row)
Close when done:
cursor.close()
conn.close()
Save results to CSV:
import csv
cursor.execute('SELECT * FROM orders LIMIT 1000')
results = cursor.fetchall()
with open('output.csv', 'w', newline='', encoding='utf-8') as f:
writer = csv.writer(f)
writer.writerow([col[0] for col in cursor.description]) # Write header
writer.writerows(results)
SQL Hints
Pass SQL hints via parameters, for example to set a timeout:
Suitable for long-running queries to avoid blocking:
import time
cursor.execute_async('SELECT count(*) FROM large_table')
while not cursor.is_job_finished():
print("Executing...")
time.sleep(1)
results = cursor.fetchall()
print(results)
Notes
commit and rollback interfaces are not supported
For large result sets, use fetchmany(size) to fetch in batches and avoid memory overflow
In production, use a connection pool to manage connections and avoid frequent creation and destruction