Store credentials in a separate configuration file

To keep your credential secure, it is recommended that you avoid writing credential information directly into your code. Instead, keep the credential information in a separate configuration file and read in the values needed to connect to the Experience Platform and Data Distiller.

As an example, you can create a file called config.ini and include the following information (along with any other information, such as dataset IDs, that would useful to save between sessions):

[Credential]
ims_org_id=<YOUR_IMS_ORG_ID>
sandbox_name=<YOUR_SANDBOX_NAME>
client_id=<YOUR_CLIENT_ID>
client_secret=<YOUR_CLIENT_SECRET>
scopes=openid, AdobeID, read_organizations, additional_info.projectedProductContext, session
tech_acct_id=<YOUR_TECHNICAL_ACCOUNT_ID>

In your notebook, you can then read the credential information into memory using the configParser package from the standard Python library:

from configparser import ConfigParser

# Create a ConfigParser object to read and store information from config.ini
config = ConfigParser()
config_path = '<PATH_TO_YOUR_CONFIG.INI_FILE>'
config.read(config_path)

You can then reference credential values within your code as follows:

org_id = config.get('Credential', 'ims_org_id')

Install aepp Python library

aepp is an Adobe-managed open-source Python library that provides functions for connecting to Data Distiller and submitting queries, as making requests to other Experience Platform services. The aepp library in turn relies on the PostgreSQL database adapter package psycopg2 for interactive Data Distiller queries. It is possible to connect to Data Distiller and query Experience Platform datasets with psycopg2 alone, but aepp provides greater convenience and additional functionality to make requests to all Experience Platform API services.

To install or upgrade aepp and psycopg2 in your environment, you can use the %pip magic command in your notebook:

%pip install --upgrade aepp
%pip install --upgrade psycopg2-binary

You can then configure the aepp library with your credential using the following code:

from configparser import ConfigParser

# Create a ConfigParser object to read and store information from config.ini
config = ConfigParser()
config_path = '<PATH_TO_YOUR_CONFIG.INI_FILE>'
config.read(config_path)

# Configure aepp with your credentials
import aepp

aepp.configure(
  org_id=config.get('Credential', 'ims_org_id'),
  sandbox=config.get('Credential', 'sandbox_name'),
  client_id=config.get('Credential', 'client_id'),
  secret=config.get('Credential', 'client_secret'),
  scopes=config.get('Credential', 'scopes'),
  tech_id=config.get('Credential', 'tech_acct_id')
)