Using the CData ODBC Driver for Salesforce Data Cloud in PyCharm



Connect to Salesforce Data Cloud as an ODBC data source in PyCharm using the CData ODBC Driver for Salesforce Data Cloud.

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 Salesforce Data Cloud 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 Salesforce Data Cloud 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 Salesforce Data Cloud

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.

Salesforce Data Cloud supports authentication via the OAuth standard.

OAuth

Set AuthScheme to OAuth.

Desktop Applications

CData provides an embedded OAuth application that simplifies authentication at the desktop.

You can also authenticate from the desktop via a custom OAuth application, which you configure and register at the Salesforce Data Cloud console. For further information, see Creating a Custom OAuth App in the Help documentation.

Before you connect, set these properties:

  • InitiateOAuth: GETANDREFRESH. You can use InitiateOAuth to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken.
  • OAuthClientId (custom applications only): The Client ID assigned when you registered your custom OAuth application.
  • OAuthClientSecret (custom applications only): The Client Secret assigned when you registered your custom OAuth application.

When you connect, the driver opens Salesforce Data Cloud's OAuth endpoint in your default browser. Log in and grant permissions to the application.

The driver then completes the OAuth process as follows:

  • Extracts the access token from the callback URL.
  • Obtains a new access token when the old one expires.
  • Saves OAuth values in OAuthSettingsLocation so that they persist across connections.
  • For other OAuth methods, including Web Applications and Headless Machines, refer to the Help documentation.

    Below is the syntax for a DSN:

    [CData SalesforceDataCloud Source] Driver = CData ODBC Driver for Salesforce Data Cloud Description = My Description

    Execute SQL to Salesforce Data Cloud

    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 SalesforceDataCloud};') cursor = cnxn.cursor() cursor.execute("SELECT [Account ID], [Account Name] FROM Account WHERE EmployeeCount = '250'") rows = cursor.fetchall() for row in rows: print(row.[Account ID], row.[Account Name])

    After connecting to Salesforce Data Cloud in PyCharm using the CData ODBC Driver, you will be able to build Python apps with access to Salesforce Data Cloud data as if it were a standard database. If you have any questions, comments, or feedback regarding this tutorial, please contact us at [email protected].

Ready to get started?

Download a free trial of the Salesforce Data Cloud ODBC Driver to get started:

 Download Now

Learn more:

Salesforce Data Cloud Icon Salesforce Data Cloud ODBC Driver

The Salesforce Data Cloud ODBC Driver is a powerful tool that allows you to connect with live data from Salesforce Data Cloud, directly from any applications that support ODBC connectivity.

Access Salesforce Data Cloud data like you would a database - read, write, and update Salesforce Data Cloud 0, etc. through a standard ODBC Driver interface.