Ready to get started?

Learn more about the CData ODBC Driver for Presto or download a free trial:

Download Now

Using the CData ODBC Driver for Presto in PyCharm

Connect to Presto as an ODBC data source in PyCharm using the CData ODBC Driver for Presto.

The CData ODBC Drivers can be used in any environment that supports loading an ODBC Driver. In this tutorial we will explore using the CData ODBC Driver for Presto from within PyCharm. Included are steps for adding the CData ODBC Driver as a data source, as well as basic PyCharm code to query the data source and display results.

To begin, this tutorial will assume that you have already installed the CData ODBC Driver for Presto as well as PyCharm.

Add Pyodbc to the Project

Follow the steps below to add the pyodbc module to your project.

  1. Click File -> Settings to open the project settings window.
  2. Click Project Interpreter from the Project: YourProjectName menu.
  3. To add pyodbc, click the + button and enter pyodbc.
  4. Click Install Package to install pyodbc.

Connect to Presto

You can now connect with an ODBC connection string or a DSN. See the Getting Started section in the CData driver documentation for a guide to creating a DSN on your OS.

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.

Below is the syntax for a DSN:

[CData Presto Source] Driver = CData ODBC Driver for Presto Description = My Description Server = 127.0.0.1 Port = 8080

Execute SQL to Presto

Instantiate a Cursor and use the execute method of the Cursor class to execute any SQL statement.

import pyodbc cnxn = pyodbc.connect('DRIVER={CData ODBC Driver for Presto};Server = 127.0.0.1;Port = 8080;') cursor = cnxn.cursor() cursor.execute("SELECT FirstName, LastName FROM Customer WHERE Id = '123456789'") rows = cursor.fetchall() for row in rows: print(row.FirstName, row.LastName)

After connecting to Presto in PyCharm using the CData ODBC Driver, you will be able to build Python apps with access to Presto data as if it were a standard database. If you have any questions, comments, or feedback regarding this tutorial, please contact us at support@cdata.com.