Credentials

You can store credentials for use with databases and data connections.

To interact with credentials API, use the Credential class.

List credentials

To retrieve the list of all credentials accessible to you, use Credential.list.

import datarobot as dr

credentials = dr.Credential.list()

Each credential object contains the credential_id string field which can be used in, for example, Batch predictions.

Basic credentials

Use the code below to store generic username and password credentials:

>>> import datarobot as dr
>>> cred = dr.Credential.create_basic(
...     name='my_db_cred',
...     user='<user>',
...     password='<password>',
... )
>>> cred
Credential('5e429d6ecf8a5f36c5693e0f', 'my_db_cred', 'basic'),

# Store cred.credential_id

>>> cred = dr.Credential.get(credential_id)
>>> cred.credential_id
'5e429d6ecf8a5f36c5693e0f'

Stored credentials can be used in Batch predictions for JDBC intake or output.

S3 credentials

You can store AWS credentials either using the following three parameters:

  • aws_access_key_id

  • aws_secret_access_key

  • aws_session_token

or by using the ID of the saved shared secure configuration:

  • config_id

>>> import datarobot as dr
>>> cred = dr.Credential.create_s3(
...     name='my_s3_cred',
...     aws_access_key_id='<aws access key id>',
...     aws_secret_access_key='<aws secret access key>',
...     aws_session_token='<aws session token>',
... )
>>> cred
Credential('5e429d6ecf8a5f36c5693e03', 'my_s3_cred', 's3'),

# Using config_id
>>> cred = dr.Credential.dr.Credential.create_s3(
...     name='my_s3_cred_with_config_id',
...     config_id='<id_of_shared_secure_configuration>',
... )
>>> cred
Credential('65ef55ef4cec97f0f733835c', 'my_s3_cred_with_config_id', 's3')

# Store cred.credential_id

>>> cred = dr.Credential.get(credential_id)
>>> cred.credential_id
'5e429d6ecf8a5f36c5693e03'

Stored credential can be used, for example, in Batch predictions for S3 intake or output.

OAuth credentials

You can store OAuth credentials in the data store.

>>> import datarobot as dr
>>> cred = dr.Credential.create_oauth(
...     name='my_oauth_cred',
...     token='<token>',
...     refresh_token='<refresh_token>',
... )
>>> cred
Credential('5e429d6ecf8a5f36c5693e0f', 'my_oauth_cred', 'oauth'),

# Store cred.credential_id

>>> cred = dr.Credential.get(credential_id)
>>> cred.credential_id
'5e429d6ecf8a5f36c5693e0f'

Snowflake key pair credentials

You can store Snowflake key pair credentials in the store. It accepts either of the following parameters:

  • private_key

  • passphrase

Or you can use the ID of the saved shared secure configuration.

  • config_id

>>> import datarobot as dr
>>> cred = dr.Credential.create_snowflake_key_pair(
...     name='my_snowflake_key_pair_cred',
...     user='<user>',
...     private_key="""<private_key>""",
...     passphrase='<passphrase>',
... )
>>> cred
Credential('65e9b55e4b0d925c678bb847', 'my_snowflake_key_pair_cred', 'snowflake_key_pair_user_account')
>>> cred = dr.Credential.create_snowflake_key_pair(
...     name='my_snowflake_key_pair_cred_with_config_id',
...     config_id='<id_of_shared_secure_configuration>',
... )
>>> cred
Credential('65e9b9494b0d925c678bb84d', 'my_snowflake_key_pair_cred_with_config_id', 'snowflake_key_pair_user_account')

Databricks access token credentials

You can store Databricks access token credentials in the data store.

>>> import datarobot as dr
>>> cred = dr.Credential.create_databricks_access_token(
...     name='my_databricks_access_token_cred',
...     databricks_access_token='<databricks_access_token>',
... )
>>> cred
Credential('65e9bace4b0d925c678bb850', 'my_databricks_access_token_cred', 'databricks_access_token_account')

Databricks service principal credentials

You can store Databricks service principal credentials in the store. It accepts either of the following parameters:

  • client_id

  • client_secret

You can also use the ID of the saved shared secure configuration.

  • config_id

>>> import datarobot as dr
>>> cred = dr.Credential.create_databricks_service_principal(
...     name='my_databricks_service_principal_cred',
...     client_id='<client_id>',
...     client_secret='<client_secret>',
... )
>>> cred
Credential('65e9bb864b0d925c678bb853', 'my_databricks_service_principal_cred', 'databricks_service_principal_account')
>>> cred = dr.Credential.create_databricks_service_principal(
...     name='my_databricks_service_principal_cred_with_config_id',
...     config_id='<id_of_shared_secure_configuration>',
... )
>>> cred
Credential('65e9bcc14b0d925c678bb85e', 'my_databricks_service_principal_cred_with_config_id', 'databricks_service_principal_account')

Azure Service Principal credentials

You can store Azure Service Principal credentials using any of the three following parameters:

  • client_id

  • client_secret

  • azure_tenant_id

You can also use the ID of the saved shared secure configuration.

  • config_id

>>> import datarobot as dr
>>> cred = dr.Credential.create_azure_service_principal(
...     name='my_azure_service_principal_cred',
...     client_id='<client id>',
...     client_secret='<client secret>',
...     azure_tenant_id='<azure tenant id>',
... )
>>> cred
Credential('66c920fc4ef80072a8225e56', 'my_azure_service_principal_cred2', 'azure_service_principal')

# Using config_id
>>> cred = dr.Credential.dr.Credential.create_azure_service_principal(
...     name='my_azure_service_principal_cred_with_config_id',
...     config_id='<id_of_shared_secure_configuration>',
... )
>>> cred
Credential('66c921aa0ff7aea1ce225e2d', 'my_azure_service_principal_cred_with_config_id', 'azure_service_principal')

# Store cred.credential_id

>>> cred = dr.Credential.get(credential_id)
>>> cred.credential_id
'66c921aa0ff7aea1ce225e2d'

ADLS OAuth credentials

You can store ADLS OAuth credentials using any of the three following parameters:

  • client_id

  • client_secret

  • oauth_scopes

You can also use the ID of the saved shared secure configuration.

  • config_id

>>> import datarobot as dr
>>> cred = dr.Credential.create_adls_oauth(
...     name='my_adls_oauth_cred',
...     client_id='<client id>',
...     client_secret='<client secret>',
...     oauth_scopes=['<oauth scope>'],
... )
>>> cred
Credential('66c9227e3b268d3278225e41', 'my_adls_oauth_cred', 'adls_gen2_oauth')

# Using config_id
>>> cred = dr.Credential.dr.Credential.create_adls_oauth(
...     name='my_adls_oauth_cred_with_config_id',
...     config_id='<id_of_shared_secure_configuration>',
... )
>>> cred
Credential('66c922b3ae75806f1d126f06', 'my_adls_oauth_cred_with_config_id', 'adls_gen2_oauth')

# Store cred.credential_id

>>> cred = dr.Credential.get(credential_id)
>>> cred.credential_id
'66c922b3ae75806f1d126f06'

Credential data

For methods that accept credential data instead of a username/password or credential ID:

{
    "credentialType": "basic",
    "user": "user123",
    "password": "pass123",
}
{
    "credentialType": "s3",
    "awsAccessKeyId": "key123",
    "awsSecretAccessKey": "secret123",
}
{
    "credentialType": "s3",
    "configId": "id123",
}
{
    "credentialType": "oauth",
    "oauthRefreshToken": "token123",
    "oauthClientId": "client123",
    "oauthClientSecret": "secret123",
}
{
    "credentialType": "snowflake_key_pair_user_account",
    "user": "user123",
    "privateKey": "privatekey123",
    "passphrase": "passphrase123",
}
{
    "credentialType": "snowflake_key_pair_user_account",
    "configId": "id123",
}
{
    "credentialType": "databricks_access_token_account",
    "databricksAccessToken": "token123",
}
{
    "credentialType": "databricks_service_principal_account",
    "clientId": "client123",
    "clientSecret": "secret123",
}
{
    "credentialType": "databricks_service_principal_account",
    "configId": "id123",
}
{
    "credentialType": "azure_service_principal",
    "clientId": "client123",
    "clientSecret": "secret123",
    "azureTenantId": "tenant123"
}
{
    "credentialType": "azure_service_principal",
    "configId": "id123",
}
{
    "credentialType": "adls_gen2_oauth",
    "clientId": "client123",
    "clientSecret": "secret123",
    "oauthScopes": ["scope123"]
}
{
    "credentialType": "adls_gen2_oauth",
    "configId": "id123",
}