How to Build an ETL App for Presto Data in Python with CData Connect AI
The rich ecosystem of Python modules lets you get to work quickly and integrate your systems more effectively. With the CData Connect AI Python SDK and the petl framework, you can build Presto-connected applications and pipelines for extracting, transforming, and loading Presto data. This article shows how to connect to Connect AI and use petl to extract, transform, and load Presto data.
The Connect AI Python SDK (cdata-connect-ai) is a DB-API 2.0 (PEP 249) compliant client, so petl can read directly from the SDK connection with etl.fromdb. There is no driver to install per source: connect with a Personal Access Token and build your pipeline.
About Presto Data Integration
Accessing and integrating live data from Trino and Presto SQL engines has never been easier with CData. Customers rely on CData connectivity to:
- Access data from Trino v345 and above (formerly PrestoSQL) and Presto v0.242 and above (formerly PrestoDB)
- Read and write access all of the data underlying your Trino or Presto instances
- Optimized query generation for maximum throughput.
Presto and Trino allow users to access a variety of underlying data sources through a single endpoint. When paired with CData connectivity, users get pure, SQL-92 access to their instances, allowing them to integrate business data with a data warehouse or easily access live data directly from their preferred tools, like Power BI and Tableau.
In many cases, CData's live connectivity surpasses the native import functionality available in tools. One customer was unable to effectively use Power BI due to the size of the datasets needed for reporting. When the company implemented the CData Power BI Connector for Presto they were able to generate reports in real-time using the DirectQuery connection mode.
Getting Started
Connect to Presto in Connect AI
CData Connect AI uses a straightforward, point-and-click interface to connect to data sources.
- Log into Connect AI, click Sources, and then click Add Connection
- Select "Presto" from the Add Connection panel
-
Enter the necessary authentication properties to connect to Presto.
Set the Server and Port connection properties to connect, in addition to any authentication properties that may be required.
To enable TLS/SSL, set UseSSL to true.
Authenticating with LDAP
In order to authenticate with LDAP, set the following connection properties:
- AuthScheme: Set this to LDAP.
- User: The username being authenticated with in LDAP.
- Password: The password associated with the User you are authenticating against LDAP with.
Authenticating with Kerberos
In order to authenticate with KERBEROS, set the following connection properties:
- AuthScheme: Set this to KERBEROS.
- KerberosKDC: The Kerberos Key Distribution Center (KDC) service used to authenticate the user.
- KerberosRealm: The Kerberos Realm used to authenticate the user with.
- KerberosSPN: The Service Principal Name for the Kerberos Domain Controller.
- KerberosKeytabFile: The Keytab file containing your pairs of Kerberos principals and encrypted keys.
- User: The user who is authenticating to Kerberos.
- Password: The password used to authenticate to Kerberos.
- Click Save & Test
- Navigate to the Permissions tab and update the user-based permissions.

Generate a Personal Access Token (PAT)
The Python SDK authenticates to Connect AI with your account email and a Personal Access Token (PAT). It is best practice to create a separate PAT for each application to maintain granularity of access.
- Click the Gear icon () at the top right of the Connect AI app to open the Settings page.
- On the Settings page, go to the Access Tokens section and click Create PAT.
- Give the PAT a name and click Create.

- The PAT is only visible at creation, so copy it and store it securely.
Install Required Modules
Install the SDK and the petl framework using the pip utility:
pip install cdata-connect-ai pip install petl
Build an ETL App for Presto Data in Python
Once the required modules are installed, you are ready to build the ETL app. Code snippets follow, but the full source code is available at the end of the article.
First, import the modules and connect to Connect AI with your account email and PAT:
import petl as etl
import cdata_connect_ai
conn = cdata_connect_ai.connect(
username="[email protected]",
password="<your_pat>",
)
Create a SQL Statement to Query Presto
Use SQL to create a statement for querying Presto. In this article, we read data from the Customer entity. Identifiers are three-part: <Connection>.<Schema>.<Table>, where the connection name defaults to the source name (for example, Presto1).
sql = (
"SELECT FirstName, LastName "
"FROM [Presto1].[Presto].[Customer] "
"WHERE Id = '123456789'"
)
Extract, Transform, and Load the Presto Data
With a connection and query in hand, use petl to extract, transform, and load the Presto data. In this example, we extract Presto data, sort the data by the LastName column, and load the data into a CSV file.
table1 = etl.fromdb(conn, sql) table2 = etl.sort(table1, 'LastName') etl.tocsv(table2, 'customer_data.csv')
Load New Rows Back into Presto
When Presto supports writes, load rows back with a batch INSERT. The SDK's executemany takes @name placeholders and a list of parameter dictionaries, one per row.
cur = conn.cursor()
cur.executemany(
"INSERT INTO [Presto1].[Presto].[Customer] (FirstName, LastName) "
"VALUES (@val1, @val2)",
[
{"@val1": "New value 1", "@val2": "New value 1"},
{"@val1": "New value 2", "@val2": "New value 2"},
],
)
print(f"Rows inserted: {cur.rowcount}")
conn.close()
Note: Even for writable sources, a read-only PAT or connection permission will reject write operations.
With the CData Connect AI Python SDK, you can work with Presto data just like you would with any database, including direct access to data in ETL packages like petl.
More Information and Free Trial
Now you can pipe live Presto data through petl using the CData Connect AI Python SDK. For more information on connecting to Presto (and hundreds of other data sources), visit the Connect AI page. Sign up for a free trial and start building data pipelines for live Presto data in Python.
Full Source Code
import petl as etl
import cdata_connect_ai
conn = cdata_connect_ai.connect(
username="[email protected]",
password="<your_pat>",
)
sql = (
"SELECT FirstName, LastName "
"FROM [Presto1].[Presto].[Customer] "
"WHERE Id = '123456789'"
)
table1 = etl.fromdb(conn, sql)
table2 = etl.sort(table1, 'LastName')
etl.tocsv(table2, 'customer_data.csv')
cur = conn.cursor()
cur.executemany(
"INSERT INTO [Presto1].[Presto].[Customer] (FirstName, LastName) "
"VALUES (@val1, @val2)",
[
{"@val1": "New value 1", "@val2": "New value 1"},
{"@val1": "New value 2", "@val2": "New value 2"},
],
)
print(f"Rows inserted: {cur.rowcount}")
conn.close()