Skip to main content

salesforce-cdp-connector

This repository publishes two Python packages for Salesforce Data Cloud:

Package Status Install
salesforce-datacloud-connector Beta — recommended for new projects pip install --pre salesforce-datacloud-connector
salesforce-cdp-connector (this package) Deprecated pip install salesforce-cdp-connector

Migration

⚠️ This package is deprecated and will be removed once salesforce-datacloud-connector reaches GA. New users and existing users should migrate to salesforce-datacloud-connector. See the v2 README for installation and usage.

salesforce-cdp-connector (deprecated)

A readonly CDP client for Python. This can be used to execute queries against CDP and load the data into python.

Usage

Installation

Install the package from Pypi using the command

pip install salesforce-cdp-connector

Quick Start

We have to create an instance of the SalesforceCDPConnection to connect to CDP.

The object can be created as follows:

Using JWT

from salesforcecdpconnector.connection import SalesforceCDPConnection

fd = open('./salesforce.key');
your_key = fd.read()

conn = SalesforceCDPConnection(login_url, 
       client_id='<client_id>', 
       username='<username>', 
       private_key=your_key
   )

Using Username and Password

from salesforcecdpconnector.connection import SalesforceCDPConnection
conn = SalesforceCDPConnection(
        'login_url', 
        'user_name', 
        'password', 
        'client_id', 
        'client_secret'
    )

Using OAuth Tokens

from salesforcecdpconnector.connection import SalesforceCDPConnection
conn = SalesforceCDPConnection(login_url, 
       client_id='<client_id>', 
       client_secret='<client_secret>', 
       core_token='<core token>'
       refresh_token='<refresh_token>'
   )

Using Client Credentials

The Client Credentials flow is ideal for server-to-server integrations where no user context is required. This flow uses only the connected app's client ID and client secret to authenticate.

from salesforcecdpconnector.connection import SalesforceCDPConnection
conn = SalesforceCDPConnection(
       login_url='<login_url>',
       client_id='<client_id>', 
       client_secret='<client_secret>'
   )

Note: To use Client Credentials flow, your connected app must be configured to allow it. See the official Salesforce documentation: Configure Client Credentials Flow for External Client Apps

Once the connection object is created the queries can be executed using cursor as follows

cur = conn.cursor()
cur.execute('<query>')
results = cur.fetchall()

The query results can also be directly extracted as a pandas dataframe

dataframe = conn.get_pandas_dataframe('<query>')

Using a non-default dataspace

conn = SalesforceCDPConnection(
        'login_url', 
        'user_name', 
        'password', 
        'client_id', 
        'client_secret',
        dataspace="my-dataspace",
    )

Once the connection object is created the queries can be executed using cursor as follows, all queries will be to this specific dataspace my-dataspace

cur = conn.cursor()
cur.execute('<query>')
results = cur.fetchall()

Creating a connected App

  1. Log in to salesforce as an admin. In the top right corner, click on the gear icon and go to step
  2. In the left hand side, under Platform Tools, go to Apps > App Manager
  3. Click on New Connected App
  4. Fill in the required Basic Information fields.
  5. Under API (Enable OAuth Settings)
    1. Click on the checkbox to Enable OAuth Settings.
    2. Provide a callback URL.
    3. In the Selected OAuth Scopes, make sure that refresh_token, api, cdp_query_api, cdp_profile_api is selected.
    4. Click on Save to save the connected app
  6. From the page that opens up, click on the Manage Consumer Details to find your client id and client secret

Fetching Refresh Token

  1. From the connected app, note down the below details:

    • Client Id
    • Client Secret
    • Callback URL
  2. Obtain the code

    1. From browser, go to the below url.
    <LOGIN_URL>/services/oauth2/authorize?response_type=code&client_id=<client_id>&redirect_uri=<callback_url>
    
    1. This will redirect you to the callback url. The redirected url will be of the form <callback url>?code=<CODE>
    2. Extract the CODE from the address bar to be used in next step. Check the network tab of browser if the addressbar doesn't show this.
  3. Get core and refresh tokens

    1. Make a post call using curl or postman to the below url using the code retrieved in previous step.
    <LOGIN_URL>/services/oauth2/token?code=<CODE>&grant_type=authorization_code&client_id=<clientId>&client_secret=<clientSecret>&redirect_uri=<callback_uri>
    
    1. The response to the above post call will be a json with access_token and refresh_token

Developing

Install UV for dependency management

https://docs.astral.sh/uv/getting-started/installation/

Download dependencies

uv sync --all-extras --dev

Build the project

uv build

Test the project

uv run pytest

Bump dependencies

uv sync --resolution highest

Functionally test the project

First you'll need to follow the instructions above Now you'll need to add the appropriate values to a .env file which you can make like so: cp .env.template .env

Now you can run the following (where the version in the .whl path is correct) and expect a query result, we also expect "salesforce" to not be present in example.py.lock

uv run --isolated --script example.py --with dist/salesforce_cdp_connector-1.0.16-py3-none-any.whl 

Metadata

Release files for salesforce-cdp-connector 1.0.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for salesforce-cdp-connector 1.0.20
File Size Uploaded
salesforce_cdp_connector-1.0.20.tar.gz 14.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for salesforce-cdp-connector 1.0.20
File Interpreter ABI Platform
salesforce_cdp_connector-1.0.20-py3-none-any.whl Python 3 none any Details

Total release size: 34.3 kB

Release files / salesforce_cdp_connector-1.0.20.tar.gz

Download URL salesforce_cdp_connector-1.0.20.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
820282bbc02cb198b8d0be98433a8227e0550e9cf31eab5e986276fb49bb6663
BLAKE2b-256 checksum
How to use checksums
ee688862ec222f627df51742fd4c142a24ecc59e869d68f98997ded9bf1ed8e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / salesforce_cdp_connector-1.0.20-py3-none-any.whl

Download URL salesforce_cdp_connector-1.0.20-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8dbee795ff65a6c48e7c5c96debe3566307e0d2807eaf7263875504df8b8c53a
BLAKE2b-256 checksum
How to use checksums
161d4c3580fe64bd43a15c3b2c2e0612e4ebfbf2ac03a8cb04390cd43d215687
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

1.0.20 This release

2 release files

1.0.19

2 release files

1.0.18

2 release files

1.0.17

2 release files

1.0.16

2 release files

1.0.15

2 release files

1.0.14

2 release files

1.0.11

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page