Save Big on Cyber Monday! Up to 40% Off
ends in   {{days}}
Days
{{timeFormat.hours}}
:
{{timeFormat.minutes}}
:
{{timeFormat.seconds}}

Connect to Salesforce and access data in Python

Accessing a Salesforce database can be fast and seamless with an Open Database Connectivity (ODBC) solution. Devart ODBC Driver for Salesforce provides full interoperability and allows you to access live Salesforce data. The driver enables you to retrieve, view, and modify Salesforce data from your Python app.

Step 1. Create a connection

Import the pyodbc module and create a connection to the database.

import pyodbc 
cnxn = pyodbc.connect('DRIVER={Devart ODBC Driver for SQLite};Direct=True;Database=mydatabase')

Step 2. Test the connection

Run an INSERT statement to test the connection to the database.

cursor = cnxn.cursor()  
cursor.execute("INSERT INTO EMP (EMPNO, ENAME, JOB, MGR) VALUES (535, 'Scott', 'Manager', 545)")

Step 3. Retrieve Salesforce data

Retrieve a result set from a query, iterate over it, and print out all records.

cursor.execute("SELECT * FROM EMP")
row = cursor.fetchone() 
while row: 
    print (row)
    row = cursor.fetchone()

How to download, install, and configure Devart ODBC Driver for Salesforce

Download the driver

Click Download in the upper-right corner of this page. Under Download for Windows, click Download next to the EXE or MSI file or—if you're not signed in—click Get Trial, sign up or sign in to your Devart account, and then click Download next to the needed file.

Install the driver

Run the downloaded installer. Click Next and follow the instructions.

The Welcome page of the Devart ODBC Driver Setup Wizard.

Start the trial period or activate the driver

If you don't have an activation key yet, select Trial; if you've already purchased a license, select Activation Key and enter your key. Then, click Next. To complete the driver installation, click Finish.

The Lisense Information page of the Devart ODBC Driver Setup Wizard.

Open ODBC Data Source Administrator

Click Start on the taskbar, type ODBC Data Sources, and select a matching result. The ODBC Data Source Administrator opens.

The ODBC Data Sources search results.

Add a data source (DSN)

Go to the User DSN or System DSN tab and click Add. Select Devart ODBC Driver for Salesforce and click Finish.

The Create New Data Source dialog in the ODBC Data Source Administrator.

Configure the DSN

On the General tab, enter a Data Source Name, Description, and Salesforce connection details. The default authentication method is OAuth 2.0. To use basic authentication, select User ID and Password from the Authentication menu.

The Devart ODBC Driver for Salesforce Configuration dialog.

Complete the configuration

Click Test Connection to make sure that all details are correct. Then, click OK to save the DSN and complete the configuration.

The Connection successful message in the Devart ODBC Driver for Salesforce Configuration dialog.

Prepare for the installation

1. Install the iODBC driver manager. It's required for the driver to work properly.
2. Go to Apple menu > System Settings > Privacy & Security. In Allow applications from under Security, select App Store & Known Developers.

Prepare for the installation

Download the driver

Click Download in the upper-right corner of this page. Under Download for macOS, click Download next to the PKG file or—if you're not signed in—click Get Trial, sign up or sign in to your Devart account, and then click Download next to the file.

Start the installation

Run the downloaded installer. Click Allow to start the installation. In the Install Devart ODBC Driver for Salesforce window, click Continue on the first page and on the next one.

Start the installation

Agree to the software license agreement

On the License page, read the agreement, click Continue, and then click Agree.

Agree to the software license agreement

Start the trial period or activate the driver

If you don't have an activation key yet, select Trial; if you've already purchased a license, select Activation Key and enter your key. Then, click Continue.

Start the trial period or activate the driver

Complete the installation

Click Install. If prompted, enter your password to allow the installation and click Install Software. After the installation finishes, click Close.

Complete the installation

Configure a data source (DSN)

Go to Finder > Applications > iODBC and open iODBC Administrator of the required bitness. On the System DSN tab (recommended), select the DSN named DEVART_SALESFORCE (it was created automatically) and click Configure.

Configure a data source (DSN)

Enter connection details

Specify the required connection details and click Ok.

Enter connection details

Complete the configuration

Click Test to make sure that all details are correct. Then, click OK twice to close the message and iODBC Data Source Administrator.

Complete the configuration

Prepare for the installation

Note: This is a flow for Ubuntu 24. For other distributions, the steps may vary.

Make sure you have an ODBC driver manager installed—we recommend using unixODBC. You can install it with sudo apt-get install libodbc2 libodbcinst2 odbcinst unixodbc.

A Terminal window showing the apt-get command to install ODBC packages on Linux.

Download the driver

Click Download in the upper-right corner of this page. Under Download for Linux, click Download next to the DEB or RPM package of the required bitness or—if you're not signed in—click Get Trial, sign up or sign in to your Devart account, and then click Download next to the package.

Open the installer location

With a DEB package, you can install the driver using the GUI. Go to the package location (by default, the package is downloaded to /home/user/Downloads). Right-click the package and select Open With App Center.

The Downloads folder in the File manager window with a context menu opened for the Debian package.

You can also use the command line to install the driver from either a DEB or RPM package and activate the installed driver. For more information, see the driver documentation.

Install the driver

In the App Center window, click Install. In the warning that appears, click Install too. If prompted for authentication, enter the password and click Authenticate.

The App Center window and a warning about a third-party package.

Configure a data source (DSN)

Open the odbc.ini file in a text editor. We're using nano, so the command is sudo nano /etc/odbc.ini. Locate the DSN named DEVART_SALESFORCE (it was created automatically) and specify the connection details.

Data Source=<your Salesforce instance>
User ID=<your Salesforce username>
Password=<your Salesforce password>
Security Token=<your Salesforce account security token>

Closing the file, save the changes.

The Terminal window showing GNU nano editing /etc/odbc.ini with the driver configuration details.

Test the connection

Run isql -v DEVART_SALESFORCE to test the connection using isql, the ODBC command-line tool. Once connected, you can run SQL queries to retrieve data from Salesforce.

The Terminal window showing successful connection to DEVART_SALESFORCE via isql.

Key features

Cross-Platform Support

Cross-platform support

  • Windows (32/64-bit)
  • macOS
  • Linux
  • Single driver for all platforms
Performance Features

Performance features

  • Connection pooling
  • Batch updates
  • Prepared statements
Unicode Support

Unicode support

Full Unicode compliance for all character sets

Standard SQL

Standard SQL

  • Aggregate functions
  • Array functions
  • Datetime functions
Advanced Data Conversion

Advanced data conversion

Bi-directional mapping between Python and ODBC data types

Simple Deployment

Simple deployment

  • Single driver installation, no additional components
  • Support for all Salesforce versions

Ready to get started?

Get started with ODBC Drivers at no cost

Get started with ODBC Drivers at no cost

Download our ODBC Drivers for a FREE 30-day trial and see them in action today!

Try ODBC Universal Bundle

Try ODBC Universal Bundle

Get universal access to data of different ODBC-compliant data sources, including major database servers and cloud services.

Need a hand?

Need a hand?

If you need any help or have questions about our tools or purchasing options, just get in touch with our team.

Popular Python integrations using other ODBC drivers for CRMs