---
schema_version: "1"
id: 18679a6b73cf20d44daf32f37d1f1f2510abb51bffe3cb87224fb1ec22aff530
title: Data 360 Python Connector
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-cloud/data-cloud-query-guide/guides/get-started-dc-python.md
canonical_url: https://developer.salesforce.com/docs/data/data-cloud-query-guide/guide/get-started-dc-python.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 5c5f50c40eedfa8ad1aba9ff2d88a1b917114c4329333df105977cc3541c7bbb
products:
  - Data 360 Query Guide
  - Data 360 Developer Documentation
---
# 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:

```nolang
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

```nolang
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

```nolang
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:

```nolang
cur = conn.cursor()
cur.execute('SELECT * FROM your_table')
```

### 3. Fetch Results

Choose one of three methods to retrieve your data:

#### Fetch One Row

```nolang
result = cur.fetchone()
```

#### Fetch All Rows

```nolang
results = cur.fetchall()
```

#### Get Pandas DataFrame

```nolang
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

- [Learn about Data 360 Query API](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/data-cloud-query-api-reference/dc-rest-api-overview.html)
- [Explore Data 360 data model objects](https://developer.salesforce.com/docs/atlas.en-us.c360a_api.meta/c360a_api/c360a_api_metadata_api.htm)
- [Understand Data 360 limits and guidelines](https://help.salesforce.com/s/articleView?id=data.c360_a_limits_and_guidelines.htm&type=5)

### 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

- Join the [Salesforce Developer Community](https://trailhead.salesforce.com/trailblazer-community/groups/0F94S000000kOWvSAM)
- Check out [Trailhead modules](https://trailhead.salesforce.com/content/learn/trails/data-cloud) on Data 360
- Explore [GitHub examples](https://github.com/forcedotcom) for Data 360 integration
