Python Salesforce Connector

In this article you will learn how to integrate Salesforce data to Python (live / bi-directional connection to Salesforce). Salesforce Connector can be used to extract/load large amount of data from/in Salesforce.com without any programming. You can use simple Table mode or Query mode with full SOQL query language support (SOQL=Salesforce.com Object Query Language)..

Using Salesforce Connector you will be able to connect, read, and write data from within Python. Follow the steps below to see how we would accomplish that.

Download  Help File  Buy 

Create ODBC Data Source (DSN) based on ZappySys Salesforce Driver

To get data from Salesforce using Python we first need to create a DSN (Data Source) which will access data from Salesforce. We will later be able to read data using Python. Perform these steps:

  1. Install ZappySys ODBC PowerPack.

  2. Open ODBC Data Sources (x64):
    Open ODBC Data Source

  3. Create a User Data Source (User DSN) based on ZappySys Salesforce Driver

    ZappySys Salesforce Driver
    Create new System DSN for ZappySys Salesforce Driver
    You should create a System DSN (instead of a User DSN) if the client application is launched under a Windows System Account, e.g. as a Windows Service. If the client application is 32-bit (x86) running with a System DSN, use ODBC Data Sources (32-bit) instead of the 64-bit version.
  4. Now, we need SalesForce Connection. Lets create it. ODBC SalesForce Driver - Create Connection

  5. Now, When you see DSN Config Editor with zappysys logo first thing you need to do is change default DSN Name at the top and Click on Preview Tab, Select Table from Tables Dropdown or you can enter or modify a SOQL query and click on Preview Data.
    This example shows how to write simple SOQL query (Salesforce Object Query Language). It uses WHERE clause. For more SOQL Queries click here.
    SOQL is similar to database SQL query language but much simpler and many features you use in database query may not be supported in SOQL (Such as JOIN clause not supported). But you can use following Queries for Insert, Update, Delete and Upsert(Update or Insert record if not found).

    SELECT * FROM Account WHERE Name like '%Oil%'
    ZappySys ODBC Driver - Select Table and Preview Data
  6. Click OK to finish creating the data source

Read data in Python from the DSN

  1. Python code to get the data:

    SalesforceDSN')
    Python code to get the data from ZappySys DSN

  2. When you run the code it will make the API call and read the data:
    Python - Extracted data from ZappySys DSN

  3. Here is Python program's code in text format:

    
        import pyodbc
        conn = pyodbc.connect('DSN=SalesforceDSN')
    
        cursor = conn.cursor()
    
        #execute query to fetch data from API service
        cursor.execute("SELECT id,title FROM products")
    
        row = cursor.fetchone()
        while row:
            print(row)
            row = cursor.fetchone()
    
        ##For loop example
        #for row in cursor:
        #    print(row)
    

  4. If you want to avoid to be dependent on a DSN name and creating multiple DSNs for each platform (x86, x64), then you can use a fully qualified connection string. Simply go to your DSN and copy the Connection String . Then in your Python code use Connection String when initializing OdbcConnection object, for example:

    conn = pyodbc.connect('DRIVER={ZappySys Salesforce Driver};ServiceUrl=https://yourservices.provider.com/api/xxxx....;AuthName=Http;')
    How to get ZappySys Driver Connection String?

    Please follow the instructions below to retrieve the connection string for the ZappySys driver.

    1. Click on the Windows Start menu.

    2. In the search bar, type ODBC and press Enter.

    3. From the search results, choose ODBC Data Sources or ODBC Data Sources (32-bit) or a similar option depending on your system architecture and ODBC driver configuration.

    4. Choose your data source from the list, then click on the Configure button.
    5. After opening the Data Source UI, you should copy the connection string to a Notepad or text file for reference.
    6. Click on Copy Connection String button.
      When you click 'Copy Connection String,' you may encounter the following option:
      Choose the third option All Settings to copy everything and click on OK button.
      zappysys-data-source-copy-connectionstring
      zappysys-data-source-copy-connectionstring

    That's it connection string has been successfully copied.

How to install `pyodbc` in the Python?

You would need to install pyodbc in Python if you intend to establish connections to databases that support ODBC (Open Database Connectivity). This module facilitates communication between Python applications and various database management systems, enabling you to perform operations such as querying, retrieving data, and managing databases. Here's how you can install pyodbc in Python:

Installation Steps:

  1. Ensure you have Python installed on your system. If not, download it from the official Python website and follow the installation instructions.

  2. Open your terminal or command prompt.

  3. Use the following command to install pyodbc using pip, the Python package installer:

    python -m pip install "pyodbc"

    Make sure you have a stable internet connection and the necessary permissions to install Python packages.


    Python - pip install pyodbc

Reasons to Install:

  • If pyodbc is not installed, your Python script will generate the following error:
    "ModuleNotFoundError: No module named 'pyodbc'"
    .
  • Database Connectivity: pyodbc allows Python to connect to various databases that support ODBC, such as Microsoft SQL Server, PostgreSQL, MySQL, and more.

  • Data Operations: It facilitates the execution of SQL queries, retrieval of data, and other database operations from within Python scripts.

  • Cross-Platform Support: pyodbc is designed to work across different operating systems, including Windows, macOS, and various Linux distributions.

  • Simplicity and Efficiency: The module provides an intuitive interface for managing database transactions and connections, simplifying the process of working with databases in Python.

By installing pyodbc, you can seamlessly integrate your Python applications with a wide range of ODBC-supported databases, enabling efficient and effective data management and analysis.

Conclusion

In this article we discussed how to connect to Salesforce in Python and integrate data without any coding. Click here to Download Salesforce Connector for Python and try yourself see how easy it is. If you still have any question(s) then ask here or simply click on live chat icon below and ask our expert (see bottom-right corner of this page).

Download Salesforce Connector for Python Documentation 


Other App Integration scenarios for Salesforce

Other Connectors for Python


Download Salesforce Connector for Python Documentation 

  • How to connect Salesforce in Python?

  • How to get Salesforce data in Python?

  • How to read Salesforce data in Python?

  • How to load Salesforce data in Python?

  • How to import Salesforce data in Python?

  • How to pull Salesforce data in Python?

  • How to push data to Salesforce in Python?

  • How to write data to Salesforce in Python?

  • How to POST data to Salesforce in Python?

  • Call Salesforce API in Python

  • Consume Salesforce API in Python

  • Salesforce Python Automate

  • Salesforce Python Integration

  • Integration Salesforce in Python

  • Consume real-time Salesforce data in Python

  • Consume realtime Salesforce API data in Python

  • Salesforce ODBC Driver | ODBC Driver for Salesforce | ODBC Salesforce Driver | SSIS Salesforce Source | SSIS Salesforce Destination

  • Connect Salesforce in Python

  • Load Salesforce in Python

  • Load Salesforce data in Python

  • Read Salesforce data in Python

  • Salesforce API Call in Python