Data 360 Python Connector

Use the Data 360 Python Connector to extract and analyze your Data 360 data in Python. The connector enables you to:

  • Query Data 360 data using SQL
  • Work with data in Pandas DataFrames
  • Create visual data models
  • Perform analytical operations
  • Build machine learning and AI models

Installation 

Install the connector from PyPI:

1pip install salesforce-cdp-connector

After successful installation, you’ll see: Successfully Installed salesforce-cdp-connector-<version>

Note

Authentication 

Choose one of two authentication methods:

Method 1: Username and Password 

  1. Create an external client app:

    • Go to Set up > App Manager > New External Client App
    • Complete the basic information
    • Enable OAuth settings
    • Enter your callback URL
    • Select required OAuth scopes
    • Save and continue
  2. Get your credentials:

    • Copy the consumer key (client ID)
    • Copy the consumer secret

Method 2: OAuth Endpoint 

  1. Create an external client app (same steps as Method 1)

  2. Select these OAuth scopes:

    • refresh_token
    • api
    • cdp_query_api
    • cdp_profile_api
  3. Get your OAuth tokens:

    • Construct the authorization URL:
      1<LOGIN_URL>/services/oauth2/authorize?response_type=code&client_id=<client_id>&redirect_uri=<callback_url>
    • Get the login URL from Set up > My Domain
    • Get the callback URL from Set up > App Manager > View External Client App > Call Back URL
    • Open the URL in your browser
    • Extract the authorization code from the redirect URL
    • Make a POST request to get tokens:
      1<YOUR_ORG_URL>/services/oauth2/token?code=<CODE>&grant_type=authorization_code&client_id=<clientId>&client_secret=<clientSecret>&redirect_uri=<callback_uri>
    • Save the access_token and refresh_token from the response

Using the Connector 

1. Create a Connection 

With Username and Password 

1from salesforcecdpconnector.connection import SalesforceCDPConnection
2
3conn = SalesforceCDPConnection(
4    login_url='your_org_url',
5    user_name='your_username',
6    password='your_password',
7    client_id='your_consumer_key',
8    client_secret='your_consumer_secret'
9)

With OAuth Tokens 

1from salesforcecdpconnector.connection import SalesforceCDPConnection
2
3conn = SalesforceCDPConnection(
4    login_url='your_org_url',
5    client_id='your_consumer_key',
6    client_secret='your_consumer_secret',
7    core_token='your_access_token',
8    refresh_token='your_refresh_token'
9)

2. Execute Queries 

Create a cursor and execute your SQL query:

1cur = conn.cursor()
2cur.execute('SELECT * FROM your_table')

3. Fetch Results 

Choose one of three methods to retrieve your data:

Fetch One Row 

1result = cur.fetchone()

Fetch All Rows 

1results = cur.fetchall()

Get Pandas DataFrame 

1df = conn.get_pandas_dataframe('SELECT * FROM your_table')

Next Steps 

After setting up the Python connector, here are some recommended next steps:

1. Explore Your Data 

  • Use the connector to query your Data 360 tables
  • Examine the schema of your data model objects
  • Try different SQL queries to understand your data structure

2. Data Analysis 

  • Create Pandas DataFrames for data analysis
  • Use Python libraries like matplotlib or seaborn for visualization
  • Perform statistical analysis on your data

3. Integration 

  • Connect the connector to your existing Python applications
  • Set up automated data extraction workflows
  • Integrate with your data pipeline tools

4. Advanced Topics 

5. Best Practices 

  • Use connection pooling for better performance
  • Implement proper error handling
  • Follow security best practices for credential management
  • Monitor your API usage and stay within limits

6. Community Resources