# Data connectivity
URL: https://docs.datarobot.com/en/docs/api/reference/sdk/data-connectivity.html

# Database connectivity

### class datarobot.DataDriver

A data driver

- Variables:

#### classmethod list(typ=None)

Returns list of available drivers.

- Parameters: typ ( DataDriverListTypes ) – If specified, filters by specified driver type.
- Returns: drivers – contains a list of available drivers.
- Return type: list of DataDriver instances

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> drivers = dr.DataDriver.list()
> >>> drivers
> [DataDriver('mysql'), DataDriver('RedShift'), DataDriver('PostgreSQL')]
> ```

#### classmethod get(driver_id)

Gets the driver.

- Parameters: driver_id ( str ) – the identifier of the driver.
- Returns: driver – the required driver.
- Return type: DataDriver

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> driver = dr.DataDriver.get('5ad08a1889453d0001ea7c5c')
> >>> driver
> DataDriver('PostgreSQL')
> ```

#### classmethod create(class_name, canonical_name, files=None, typ=None, database_driver=None)

Creates the driver. Only available to admin users.

- Parameters:
- Returns: driver – the created driver.
- Return type: DataDriver
- Raises: ClientError – raised if user is not granted for Can manage JDBC database drivers feature

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> driver = dr.DataDriver.create(
> ...     class_name='org.postgresql.Driver',
> ...     canonical_name='PostgreSQL',
> ...     files=['/tmp/postgresql-42.2.2.jar']
> ... )
> >>> driver
> DataDriver('PostgreSQL')
> ```

#### update(class_name=None, canonical_name=None)

Updates the driver. Only available to admin users.

- Parameters:
- Raises: ClientError – raised if user is not granted for Can manage JDBC database drivers feature
- Return type: None

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> driver = dr.DataDriver.get('5ad08a1889453d0001ea7c5c')
> >>> driver.canonical_name
> 'PostgreSQL'
> >>> driver.update(canonical_name='postgres')
> >>> driver.canonical_name
> 'postgres'
> ```

#### delete()

Removes the driver. Only available to admin users.

- Raises: ClientError – raised if user is not granted for Can manage JDBC database drivers feature
- Return type: None

### class datarobot.Connector

A connector

- Variables:

#### classmethod list(data_type=None)

Returns list of available connectors.

- Parameters: data_type ( DataTypes ) – If specified, returns the connectors that support the specified data type. If not specified, it will
  default to DataTypes.ALL
- Returns: connectors – contains a list of available connectors.
- Return type: list of Connector instances

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> connectors = dr.Connector.list()
> >>> connectors
> [Connector('ADLS Gen2 Connector'), Connector('S3 Connector')]
> ```

#### classmethod get(connector_id)

Gets the connector.

- Parameters: connector_id ( str ) – the identifier of the connector.
- Returns: connector – the required connector.
- Return type: Connector

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> connector = dr.Connector.get('5fe1063e1c075e0245071446')
> >>> connector
> Connector('ADLS Gen2 Connector')
> ```

#### classmethod create(file_path=None, connector_type=None)

Creates the connector from a jar file. Only available to admin users.

- Parameters:
- Returns: connector – the created connector.
- Return type: Connector
- Raises: ClientError – raised if user is not granted for Can manage connectors feature

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> connector = dr.Connector.create('/tmp/connector-adls-gen2.jar')
> >>> connector
> Connector('ADLS Gen2 Connector')
> ```

#### update(file_path)

Updates the connector with new jar file. Only available to admin users.

- Parameters: file_path ( str ) – (Deprecated in version v3.6)
  the file path on file system file_path(s) for the java-based connector.
- Returns: connector – the updated connector.
- Return type: Connector
- Raises: ClientError – raised if user is not granted for Can manage connectors feature

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> connector = dr.Connector.get('5fe1063e1c075e0245071446')
> >>> connector.base_name
> 'connector-adls-gen2.jar'
> >>> connector.update('/tmp/connector-s3.jar')
> >>> connector.base_name
> 'connector-s3.jar'
> ```

#### delete()

Removes the connector. Only available to admin users.

- Raises: ClientError – raised if user is not granted for Can manage connectors feature
- Return type: None

### class datarobot.DataStore

A data store. Represents database

- Variables:

#### classmethod list(typ=None, name=None, substitute_url_parameters=False, data_type=None)

Returns list of available data stores.

- Parameters:
- Returns: data_stores – contains a list of available data stores.
- Return type: list of DataStore instances

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> data_stores = dr.DataStore.list()
> >>> data_stores
> [DataStore('Demo'), DataStore('Airlines')]
> ```

#### classmethod get(data_store_id, substitute_url_parameters=False)

Gets the data store.

- Parameters:
- Returns: data_store – the required data store.
- Return type: DataStore

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> data_store = dr.DataStore.get('5a8ac90b07a57a0001be501e')
> >>> data_store
> DataStore('Demo')
> ```

#### classmethod create(data_store_type, canonical_name, driver_id=None, jdbc_url=None, fields=None, connector_id=None)

Creates the data store.

- Parameters:
- Returns: data_store – the created data store.
- Return type: DataStore

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> data_store = dr.DataStore.create(
> ...     data_store_type='jdbc',
> ...     canonical_name='Demo DB',
> ...     driver_id='5a6af02eb15372000117c040',
> ...     jdbc_url='jdbc:postgresql://my.db.address.org:5432/perftest'
> ... )
> >>> data_store
> DataStore('Demo DB')
> ```

#### update(canonical_name=None, driver_id=None, connector_id=None, jdbc_url=None, fields=None)

Updates the data store.

- Parameters:
- Return type: None

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> data_store = dr.DataStore.get('5ad5d2afef5cd700014d3cae')
> >>> data_store
> DataStore('Demo DB')
> >>> data_store.update(canonical_name='Demo DB updated')
> >>> data_store
> DataStore('Demo DB updated')
> ```

#### delete()

Removes the DataStore

- Return type: None

#### test(username=None, password=None, credential_id=None, use_kerberos=None, credential_data=None, set_default_credential=False)

Tests database connection.

Changed in version v3.2: Added credential_id, use_kerberos and credential_data optional params and made
username and password optional.

Changed in version v3.9: If credential_id is provided and set_default_credential is True and the connection test is successful,
the credential is set as the default for this data store.

- Parameters:
- Returns: message – message with status.
- Return type: dict
- Raises: CredentialsError – If unable to set the provided credential_id as default for this data store.

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> data_store = dr.DataStore.get('5ad5d2afef5cd700014d3cae')
> >>> data_store.test(username='db_username', password='db_password')
> {'message': 'Connection successful'}
> ```

#### schemas(username, password)

Returns list of available schemas.

- Parameters:
- Returns: response – dict with database name and list of str - available schemas
- Return type: dict

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> data_store = dr.DataStore.get('5ad5d2afef5cd700014d3cae')
> >>> data_store.schemas(username='db_username', password='db_password')
> {'catalog': 'perftest', 'schemas': ['demo', 'information_schema', 'public']}
> ```

#### tables(username, password, schema=None)

Returns list of available tables in schema.

- Parameters:
- Returns: response – dict with catalog name and tables info
- Return type: dict

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> data_store = dr.DataStore.get('5ad5d2afef5cd700014d3cae')
> >>> data_store.tables(username='db_username', password='db_password', schema='demo')
> {'tables': [{'type': 'TABLE', 'name': 'diagnosis', 'schema': 'demo'}, {'type': 'TABLE',
> 'name': 'kickcars', 'schema': 'demo'}, {'type': 'TABLE', 'name': 'patient',
> 'schema': 'demo'}, {'type': 'TABLE', 'name': 'transcript', 'schema': 'demo'}],
> 'catalog': 'perftest'}
> ```

#### classmethod from_server_data(data, keep_attrs=None)

Instantiate an object of this class using the data directly from the server,
meaning that the keys may have the wrong camel casing

- Parameters:
- Return type: DataStore

#### get_shared_roles()

Retrieve what users have access to this data store

Added in version v3.2.

- Return type: list of SharingRole

#### share(access_list)

Modify the ability of users to access this data store

Added in version v2.14.

- Parameters: access_list ( list of SharingRole ) – the modifications to make.
- Return type: None
- Raises: datarobot.ClientError : – if you do not have permission to share this data store, if the user you’re sharing with
      doesn’t exist, if the same user appears multiple times in the access_list, or if these
      changes would leave the data store without an owner.

> [!NOTE] Examples
> The [SharingRole](https://docs.datarobot.com/en/docs/api/reference/sdk/data-registry.html#datarobot.models.sharing.SharingRole) class is needed in order to
> share a Data Store with one or more users.
> 
> For example, suppose you had a list of user IDs you wanted to share this DataStore with. You could use
> a loop to generate a list of [SharingRole](https://docs.datarobot.com/en/docs/api/reference/sdk/data-registry.html#datarobot.models.sharing.SharingRole) objects for them,
> and bulk share this Data Store.
> 
> ```
> >>> import datarobot as dr
> >>> from datarobot.models.sharing import SharingRole
> >>> from datarobot.enums import SHARING_ROLE, SHARING_RECIPIENT_TYPE
> >>>
> >>> user_ids = ["60912e09fd1f04e832a575c1", "639ce542862e9b1b1bfa8f1b", "63e185e7cd3a5f8e190c6393"]
> >>> sharing_roles = []
> >>> for user_id in user_ids:
> ...     new_sharing_role = SharingRole(
> ...         role=SHARING_ROLE.CONSUMER,
> ...         share_recipient_type=SHARING_RECIPIENT_TYPE.USER,
> ...         id=user_id,
> ...         can_share=True,
> ...     )
> ...     sharing_roles.append(new_sharing_role)
> >>> dr.DataStore.get('my-data-store-id').share(access_list)
> ```
> 
> Similarly, a [SharingRole](https://docs.datarobot.com/en/docs/api/reference/sdk/data-registry.html#datarobot.models.sharing.SharingRole) instance can be used to
> remove a user’s access if the `role` is set to `SHARING_ROLE.NO_ROLE`, like in this example:
> 
> ```
> >>> import datarobot as dr
> >>> from datarobot.models.sharing import SharingRole
> >>> from datarobot.enums import SHARING_ROLE, SHARING_RECIPIENT_TYPE
> >>>
> >>> user_to_remove = "foo.bar@datarobot.com"
> ... remove_sharing_role = SharingRole(
> ...     role=SHARING_ROLE.NO_ROLE,
> ...     share_recipient_type=SHARING_RECIPIENT_TYPE.USER,
> ...     username=user_to_remove,
> ...     can_share=False,
> ... )
> >>> dr.DataStore.get('my-data-store-id').share(roles=[remove_sharing_role])
> ```

### class datarobot.DataSource

A data source. Represents data request

- Variables:

#### classmethod list(typ=None)

Returns list of available data sources.

- Parameters: typ ( DataStoreListTypes ) – If specified, filters by specified datasource type. If not specified it will
  default to DataStoreListTypes.DATABASES
- Returns: data_sources – contains a list of available data sources.
- Return type: list of DataSource instances

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> data_sources = dr.DataSource.list()
> >>> data_sources
> [DataSource('Diagnostics'), DataSource('Airlines 100mb'), DataSource('Airlines 10mb')]
> ```

#### classmethod get(data_source_id)

Gets the data source.

- Parameters: data_source_id ( str ) – the identifier of the data source.
- Returns: data_source – the requested data source.
- Return type: DataSource

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> data_source = dr.DataSource.get('5a8ac9ab07a57a0001be501f')
> >>> data_source
> DataSource('Diagnostics')
> ```

#### classmethod create(data_source_type, canonical_name, params)

Creates the data source.

- Parameters:
- Returns: data_source – the created data source.
- Return type: DataSource

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> params = dr.DataSourceParameters(
> ...     data_store_id='5a8ac90b07a57a0001be501e',
> ...     query='SELECT * FROM airlines10mb WHERE "Year" >= 1995;'
> ... )
> >>> data_source = dr.DataSource.create(
> ...     data_source_type='jdbc',
> ...     canonical_name='airlines stats after 1995',
> ...     params=params
> ... )
> >>> data_source
> DataSource('airlines stats after 1995')
> ```

#### update(canonical_name=None, params=None)

Creates the data source.

- Parameters:
- Return type: None

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> data_source = dr.DataSource.get('5ad840cc613b480001570953')
> >>> data_source
> DataSource('airlines stats after 1995')
> >>> params = dr.DataSourceParameters(
> ...     query='SELECT * FROM airlines10mb WHERE "Year" >= 1990;'
> ... )
> >>> data_source.update(
> ...     canonical_name='airlines stats after 1990',
> ...     params=params
> ... )
> >>> data_source
> DataSource('airlines stats after 1990')
> ```

#### delete()

Removes the DataSource

- Return type: None

#### classmethod from_server_data(data, keep_attrs=None)

Instantiate an object of this class using the data directly from the server,
meaning that the keys may have the wrong camel casing

- Parameters:
- Return type: TypeVar ( TDataSource , bound= DataSource)

#### get_access_list()

Retrieve what users have access to this data source

Added in version v2.14.

- Return type: list of SharingAccess

#### share(access_list)

Modify the ability of users to access this data source

Added in version v2.14.

- Parameters: access_list ( list of SharingAccess ) – The modifications to make.
- Return type: None
- Raises: datarobot.ClientError: – If you do not have permission to share this data source, if the user you’re sharing with
      doesn’t exist, if the same user appears multiple times in the access_list, or if these
      changes would leave the data source without an owner.

> [!NOTE] Examples
> Transfer access to the data source from [old_user@datarobot.com](mailto:old_user@datarobot.com) to [new_user@datarobot.com](mailto:new_user@datarobot.com)
> 
> ```
> from datarobot.enums import SHARING_ROLE
> from datarobot.models.data_source import DataSource
> from datarobot.models.sharing import SharingAccess
> 
> new_access = SharingAccess(
>     "new_user@datarobot.com",
>     SHARING_ROLE.OWNER,
>     can_share=True,
> )
> access_list = [
>     SharingAccess("old_user@datarobot.com", SHARING_ROLE.OWNER, can_share=True),
>     new_access,
> ]
> 
> DataSource.get('my-data-source-id').share(access_list)
> ```

#### create_dataset(username=None, password=None, do_snapshot=None, persist_data_after_ingestion=None, categories=None, credential_id=None, use_kerberos=None)

Create a [Dataset](https://docs.datarobot.com/en/docs/api/reference/sdk/data-registry.html#datarobot.models.Dataset) from this data source.

Added in version v2.22.

- Parameters:
- Returns: response – The Dataset created from the uploaded data
- Return type: Dataset

### class datarobot.DataSourceParameters

Data request configuration

- Variables:

# JDBC data preview

Preview data from a JDBC URL by executing SQL without creating a data store.

### class datarobot.JdbcPreview

JDBC data preview API: run SQL against a JDBC URL and get a row-limited preview
without creating a data store.

Entry-point class with [preview()](https://docs.datarobot.com/en/docs/api/reference/sdk/data-connectivity.html#datarobot.JdbcPreview.preview) returning a [JdbcPreviewData](https://docs.datarobot.com/en/docs/api/reference/sdk/data-connectivity.html#datarobot.JdbcPreviewData).

#### classmethod preview(jdbc_url, sql, max_rows=1000, parameters=None)

Preview data from a JDBC URL by executing SQL without creating a data store.

Executes the given SQL against the JDBC URL and returns a row-limited preview.
Connection credentials and parameters may be specified in the JDBC URL and/or
in the `parameters` dict (e.g.`user`, `password`, `ssl`, `timeout`).

- Parameters:
- Returns: Object with columns (list of column names), records (list of rows),
  and result_schema (list of JdbcResultSchemaEntry ), if returned by the server.
- Return type: JdbcPreviewData

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> preview = dr.JdbcPreview.preview(
> ...     jdbc_url='jdbc:postgresql://localhost:5432/mydb',
> ...     sql='SELECT * FROM public.users',
> ...     max_rows=5,
> ...     parameters={'user': 'dbuser', 'password': 'secret'},
> ... )
> >>> preview.columns
> ['id', 'name', 'email']
> >>> len(preview.records)
> 5
> ```

### class datarobot.JdbcPreviewData

A JDBC data preview: columns, records, and optional result schema from running
SQL against a JDBC URL.

### class datarobot.JdbcResultSchemaEntry

Column metadata for one column in a JDBC data preview result schema.

Returned as elements of the `result_schema` attribute of [JdbcPreviewData](https://docs.datarobot.com/en/docs/api/reference/sdk/data-connectivity.html#datarobot.JdbcPreviewData). Built via
validation in [JdbcPreviewData](https://docs.datarobot.com/en/docs/api/reference/sdk/data-connectivity.html#datarobot.JdbcPreviewData).

- Variables:

# Data store

### class datarobot.models.data_store.TestResponse

### class datarobot.models.data_store.SchemasResponse

### class datarobot.models.data_store.TablesResponse

---
