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:

pip install salesforce-cdp-connector

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

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:
      <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:
      <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

from salesforcecdpconnector.connection import SalesforceCDPConnection

conn = SalesforceCDPConnection(
    login_url='your_org_url',
    user_name='your_username',
    password='your_password',
    client_id='your_consumer_key',
    client_secret='your_consumer_secret'
)

With OAuth Tokens

from salesforcecdpconnector.connection import SalesforceCDPConnection

conn = SalesforceCDPConnection(
    login_url='your_org_url',
    client_id='your_consumer_key',
    client_secret='your_consumer_secret',
    core_token='your_access_token',
    refresh_token='your_refresh_token'
)

2. Execute Queries

Create a cursor and execute your SQL query:

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

3. Fetch Results

Choose one of three methods to retrieve your data:

Fetch One Row

result = cur.fetchone()

Fetch All Rows

results = cur.fetchall()

Get Pandas DataFrame

df = 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