---
title: Read data shared with bearer tokens
description: Learn how to read data that has been shared with you using the OpenSharing open sharing protocol, which uses a credential file (token-based security) for access.
canonical_url: https://docs.databricks.com/aws/en/opensharing/read-data-open
---

# Read data shared with bearer tokens

This page describes how to read data shared with you using the OpenSharing *open sharing* protocol with bearer tokens. It includes instructions for reading shared data using the following tools:

* [Iceberg clients](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#iceberg)
* [Apache Spark](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#apache-spark)
* [Pandas](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#pandas)
* [Power BI](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#power-bi)
* [Tableau](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#tableau)

In this sharing model, you use a credential file, shared with a member of your team by the data provider, to gain secure read access to shared data. Access persists as long as the credential is valid and the provider continues to share the data. Providers manage credential expiration and rotation. Updates to the data are available in near real time. You can read and make copies of the shared data, but you cannot modify the source data.

> [!NOTE]
>
> If data has been shared with you using Databricks-to-Databricks OpenSharing, you don't need a credential file to access data, and this page doesn't apply to you. Instead, see [Read data shared using Databricks-to-Databricks OpenSharing (for recipients)](https://docs.databricks.com/aws/en/opensharing/read-data-databricks.md).

The following sections describe how to use Apache Spark, `pandas`, Power BI, and Iceberg clients to access and read shared data using the credential file. For a full list of OpenSharing connectors and information about how to use them, see the [OpenSharing open source documentation](https://opensharing.io). If you run into trouble accessing the shared data, contact the data provider.

## Prerequisites

A member of your team must download the credential file shared by the data provider and use a secure channel to share that file or file location with you. See [Get access in the Databricks-to-Open sharing model](https://docs.databricks.com/aws/en/opensharing/recipient.md#get-access-open).

For connector-specific documentation, see [the download credentials page](https://oregon.cloud.databricks.com/delta-sharing/download-credentials).

## <a id="iceberg" />Iceberg clients: Read shared data

Use external Iceberg clients, such as Snowflake, Trino, Flink, and Spark, to read shared data assets with zero-copy access using the [Apache Iceberg REST Catalog API](https://github.com/apache/iceberg/blob/main/open-api/rest-catalog-open-api.yaml).

### Obtain connection credentials

Before you access shared data assets with external Iceberg clients, gather the following credentials:

* The Iceberg REST Catalog endpoint
* A valid Bearer token
* The share name
* (Optional) The namespace or schema name
* (Optional) The table name

The Iceberg REST Catalog endpoint (`icebergEndpoint`) and Bearer token are found in the credential file shared with you by your data provider. For more information, see [Prerequisites](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#prerequisites). The share name, namespace, and table name can be discovered programmatically using OpenSharing APIs.

> [!IMPORTANT]
>
> The `icebergEndpoint` is found in the credential file and has the format `<workspace-url>/api/2.0/delta-sharing/metastores/<metastore-id>/iceberg`.

The following examples show how to obtain the additional credentials. Enter the endpoint, Iceberg endpoint, and the Bearer token from the credential file where needed:

```shell
// List shares
curl -X GET "<endpoint>/shares" \
   -H "Authorization: Bearer <bearerToken>"

// List namespaces
curl -X GET "<icebergEndpoint>/v1/shares/<share>/namespaces" \
   -H "Authorization: Bearer <bearerToken>"

// List tables
curl -X GET "<icebergEndpoint>/v1/shares/<share>/namespaces/<namespace>/tables" \
   -H "Authorization: Bearer <bearerToken>"
```

> [!NOTE]
>
> This method always retrieves the most up-to-date list of assets. However, it requires internet access and can be harder to integrate in no-code environments.

### <a id="configure-catalog" />Configure Iceberg catalog

After you obtain the necessary connection credentials, configure your client to use the Iceberg REST Catalog endpoints to create and query tables.

1. For each share, create a catalog integration.

   ```sql
   USE ROLE ACCOUNTADMIN;

   CREATE OR REPLACE CATALOG INTEGRATION <CATALOG_PLACEHOLDER>
   CATALOG_SOURCE = ICEBERG_REST
   TABLE_FORMAT = ICEBERG
   REST_CONFIG = (
      CATALOG_URI = '<icebergEndpoint>',
      WAREHOUSE = '<share_name>',
      ACCESS_DELEGATION_MODE = VENDED_CREDENTIALS
   )
   REST_AUTHENTICATION = (
      TYPE = BEARER,
      BEARER_TOKEN = '<bearerToken>'
   )
   ENABLED = TRUE;
   ```

2. Optionally, add `REFRESH_INTERVAL_SECONDS` to keep metadata up to date. Set the value based on your catalog update frequency.

   ```sql
   REFRESH_INTERVAL_SECONDS = 30
   ```

3. After the catalog is configured, create a database from the catalog. This automatically creates all schemas and tables in that catalog.

   ```sql
   CREATE DATABASE <DATABASE_PLACEHOLDER>
   LINKED_CATALOG = (
      CATALOG = <CATALOG_PLACEHOLDER>
   );
   ```

4. To confirm that the sharing is successful, query from a table in the database. You should see the shared data from Databricks.

If the result is empty or an error occurs, follow these common troubleshooting steps:

* Double-check the privileges, snapshot generation status, and REST credentials.
* Contact your data provider.
* See the documentation specific to your Iceberg client.

### <a id="iceberg-examples" />Example: Access shared tables using different Iceberg clients

The following examples show how to access openshared tables using external Iceberg clients, such as Snowflake, Apache Spark, PyIceberg, and REST API, after obtaining your connection credentials. For more on obtaining connection credentials, see [Prerequisites](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#prerequisites).

#### Snowflake

To read shared data assets in Snowflake, upload the credential file you downloaded and generate the necessary SQL command:

1. From your OpenSharing activation link, click the Snowflake icon.

2. On the Snowflake integration page, upload the credential file you received from the data provider.

   ![Upload credential file in Snowflake](https://docs.databricks.com/aws/en/images/opensharing/upload-cred-snowflake.png)

3. After loading the credential, choose the share you want to access in Snowflake.

4. Click **Generate SQL** after selecting the desired assets.

   ![Generate SQL command for Snowflake](https://docs.databricks.com/aws/en/images/opensharing/sql-command-snowflake.png)

5. Copy and paste the generated SQL into your Snowflake worksheet. Replace `CATALOG_PLACEHOLDER` with the name of the catalog you want to use and `DATABASE_PLACEHOLDER` with the name of the database you want to use.

**Limitations**

Connecting to the Iceberg REST Catalog in Snowflake has the following limitations:

* The metadata file doesn't automatically update with the latest snapshot. You must rely on auto-refresh or manual refreshes.
* R2 is not supported.
* All [Iceberg client limitations](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#iceberg-client-limitations) apply.

#### Apache Spark

To access shared tables using Apache Spark, configure the Iceberg REST Catalog API with the following settings. Replace `<spark-catalog-name>` with a name for your catalog, and provide your connection credentials:

```ini
"spark.sql.extensions": "org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions",

# Configuration for accessing tables shared using Delta Sharing
"spark.sql.catalog.<spark-catalog-name>":"org.apache.iceberg.spark.SparkCatalog",
"spark.sql.catalog.<spark-catalog-name>.type": "rest",
"spark.sql.catalog.<spark-catalog-name>.uri": "<icebergEndpoint>",
"spark.sql.catalog.<spark-catalog-name>.token": "<bearerToken>",
"spark.sql.catalog.<spark-catalog-name>.warehouse":"<share_name>",
"spark.sql.catalog.<spark-catalog-name>.scope":"all-apis"
```

#### PyIceberg

[PyIceberg](https://py.iceberg.apache.org/) is a Python implementation for accessing Iceberg tables without using a JVM. PyIceberg requires `pyarrow` for table operations such as reading data and inspecting table metadata. Install PyIceberg with the `pyarrow` extra:

```bash
pip install "pyiceberg[pyarrow]"
```

To access shared tables, add the following catalog configuration to your PyIceberg configuration file:

```yaml
catalog:
  delta_sharing:
    type: rest
    uri: <icebergEndpoint>
    warehouse: <share_name>
    token: <bearerToken>
```

#### REST API

Use a REST API call like the following `curl` example to load a table and retrieve its metadata along with temporary credentials for accessing the data files:

```bash
curl -X GET -H "Authorization: Bearer <bearerToken>" -H "Accept: application/json" \
<icebergEndpoint>/v1/shares/<share_name>/namespaces/<schema_name>/tables/<table_name>
```

The response includes the Iceberg table metadata, the S3 location, and temporary AWS credentials that allow your client to read the data files:

```json
{
  "metadata-location": "s3://bucket/path/to/iceberg/table/metadata/file",
  "metadata": { <iceberg-table-metadata-json> },
  "config": {
    "expires-at-ms": "<epoch-ts-in-millis>",
    "s3.access-key-id": "<temporary-s3-access-key-id>",
    "s3.session-token": "<temporary-s3-session-token>",
    "s3.secret-access-key": "<temporary-secret-access-key>",
    "client.region": "<aws-bucket-region-for-metadata-location>"
  }
}
```

### <a id="iceberg-client-limitations" />Iceberg client limitations

The following limitations apply when querying OpenSharing data from Iceberg clients:

* When listing tables in a namespace, if the namespace contains more than 100 shared views, the response is limited to the first 100 views.

## <a id="apache-spark" />Apache Spark: Read shared data

Follow these steps to access shared data using Spark 3.5 or above. If you use an earlier version of Apache Spark, upgrade to Apache Spark 3.5 or above. If you only need to load shared tables into Python, use the [pandas](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#pandas) instructions instead, which don't require Java or Apache Spark.

These instructions assume that you have access to the credential file that was shared by the data provider. See [Get access in the Databricks-to-Open sharing model](https://docs.databricks.com/aws/en/opensharing/recipient.md#get-access-open).

> [!IMPORTANT]
>
> Ensure your credential file is accessible by Apache Spark by using an absolute path. The path can refer to a cloud object or Unity Catalog volume.

> [!NOTE]
>
> If you are using Spark on a Databricks workspace that is enabled for Unity Catalog, and you used the import provider UI to import the provider and share, the instructions in this section do not apply to you. You can access shared tables just as you would any other table that is registered in Unity Catalog. You do not need to install the `delta-sharing` Python connector or provide the path to the credential file. See [Import a provider and read shared data in Databricks](https://docs.databricks.com/aws/en/opensharing/read-data-open-databricks.md).

### <a id="spark-requirements" />Requirements

* Java 17 or above for Apache Spark 4.x, or Java 8, 11, or 17 for Apache Spark 3.5. To check your Java version, run `java -version`.
* Python 3.10 or above to install the latest OpenSharing Python connector. See [Python version requirements](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#python-connector-version).
* The OpenSharing Spark connector release that matches your Apache Spark and Scala versions. The Spark connector is a Java package. It is separate from the `delta-sharing` Python package, and you need both to read shared data with PySpark. See [Choose a Spark connector version](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#spark-connector-versions).

### <a id="install-spark-connectors" />Install the OpenSharing Python and Spark connectors

The following steps use PySpark, the Python API for Apache Spark.

1. Install PySpark and the [delta-sharing Python connector](https://delta.io/connectors/). Pin PySpark to a version that has a matching Spark connector. See [Choose a Spark connector version](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#spark-connector-versions). For information about Python connector limitations, see [ OpenSharing Python connector limitations](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#python-limitations).

   ```bash
   pip install "pyspark==4.2.*" delta-sharing
   ```

2. Check your Apache Spark and Scala versions:

   ```bash
   pyspark --version
   ```

   The output includes the Apache Spark version (for example, `version 4.2.0`) and the Scala and Java versions (for example, `Using Scala version 2.13.18, OpenJDK 64-Bit Server VM, 17.0.15`).

3. Start the PySpark shell with the Spark connector that matches your Apache Spark version. The following command uses the Spark connector for Apache Spark 4.2:

   ```bash
   pyspark --packages io.delta:delta-sharing-spark_2.13:4.4.1
   ```

   The `--packages` option downloads the Spark connector and its dependencies from Maven Central the first time you run it. To use Scala instead of Python, run `spark-shell` with the same `--packages` option. If PySpark fails to start or can't load the Spark connector, see [Spark connector setup errors with Open Source Spark](https://docs.databricks.com/aws/en/opensharing/troubleshooting.md#spark-connector-setup).

   If your network blocks access to Maven Central, add the `--repositories` option with the URL of a Maven repository mirror that your organization provides:

   ```bash
   pyspark --packages io.delta:delta-sharing-spark_2.13:4.4.1 --repositories <maven-mirror-url>
   ```

   If you plan to read a change data feed or run streaming queries on [tables with deletion vectors or column mapping enabled](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#deletion-vectors), start the shell with the Delta Lake SQL extension and catalog that those examples use. Set these options when you start the shell, because they can't be changed after the shell creates its Spark session:

   ```bash
   pyspark --packages io.delta:delta-sharing-spark_2.13:4.4.1 \
     --conf spark.sql.extensions=io.delta.sql.DeltaSparkSessionExtension \
     --conf spark.sql.catalog.spark_catalog=org.apache.spark.sql.delta.catalog.DeltaCatalog
   ```

### <a id="spark-connector-versions" />Choose a Spark connector version

The Spark connector's Maven coordinate has the format `io.delta:delta-sharing-spark_<scala-version>:<connector-version>`. Both parts must match your Apache Spark installation:

* `<scala-version>` is the Scala version that Apache Spark was built with. PySpark 4.x from PyPI uses Scala 2.13. PySpark 3.5 from PyPI uses Scala 2.12.
* `<connector-version>` is a Spark connector release built for your Apache Spark version. Spark connector releases use the same version numbers as Delta Lake releases.

The following table lists compatible combinations:

| PySpark version | Java version | Spark connector                           |
| --------------- | ------------ | ----------------------------------------- |
| 4.2.x           | 17 or above  | `io.delta:delta-sharing-spark_2.13:4.4.1` |
| 4.1.x           | 17 or above  | `io.delta:delta-sharing-spark_2.13:4.3.1` |
| 3.5.x           | 8, 11, or 17 | `io.delta:delta-sharing-spark_2.12:3.3.3` |

For other Apache Spark versions, see [Compatibility with Apache Spark](https://docs.delta.io/releases/) in the Delta Lake documentation. A newly released version of Apache Spark might not have a matching Spark connector yet. In that case, install the previous version of PySpark.

If reading a shared table fails with a `NoClassDefFoundError` or `NoSuchMethodError`, the Spark connector doesn't match your Apache Spark or Scala version. See [Spark connector built for a different Scala version](https://docs.databricks.com/aws/en/opensharing/troubleshooting.md#spark-scala-mismatch) and [Spark connector built for a different Spark version](https://docs.databricks.com/aws/en/opensharing/troubleshooting.md#spark-version-mismatch).

### List shared tables using Spark

List the tables in the share. In the following example, replace `<profile-path>` with the location of the credential file.

```python
import delta_sharing

client = delta_sharing.SharingClient(f"<profile-path>/config.share")

client.list_all_tables()
```

The result is an array of tables, along with metadata for each table. The following output shows two tables:

```console
Out[10]: [Table(name='example_table', share='example_share_0', schema='default'), Table(name='other_example_table', share='example_share_0', schema='default')]
```

If the output is empty or doesn't contain the tables you expect, contact the data provider.

### Access shared data using Spark

Run the following, replacing these variables:

* `<profile-path>`: the location of the credential file.
* `<share-name>`: the value of `share=` for the table.
* `<schema-name>`: the value of `schema=` for the table.
* `<table-name>`: the value of `name=` for the table.
* `<version-as-of>`: optional. The version of the table to load the data. Only works if the data provider shares the history of the table. Requires `delta-sharing-spark` 0.5.0 or above.
* `<timestamp-as-of>`: optional. Load the data at the version before or at the given timestamp. Only works if the data provider shares the history of the table. Requires `delta-sharing-spark` 0.6.0 or above.

#### Python

```python
delta_sharing.load_as_spark(f"<profile-path>#<share-name>.<schema-name>.<table-name>", version=<version-as-of>)

spark.read.format("deltaSharing")\
.option("versionAsOf", <version-as-of>)\
.load("<profile-path>#<share-name>.<schema-name>.<table-name>")\
.limit(10)

delta_sharing.load_as_spark(f"<profile-path>#<share-name>.<schema-name>.<table-name>", timestamp=<timestamp-as-of>)

spark.read.format("deltaSharing")\
.option("timestampAsOf", <timestamp-as-of>)\
.load("<profile-path>#<share-name>.<schema-name>.<table-name>")\
.limit(10)
```

#### Scala

```scala
spark.read.format("deltaSharing")
.option("versionAsOf", <version-as-of>)
.load("<profile-path>#<share-name>.<schema-name>.<table-name>")
.limit(10)

spark.read.format("deltaSharing")
.option("timestampAsOf", <version-as-of>)
.load("<profile-path>#<share-name>.<schema-name>.<table-name>")
.limit(10)
```

### <a id="spark-sql" />Query shared data using SQL

To query a shared table using SQL, create a table that uses the `deltaSharing` format, and then query it. Replace the variables as described in the previous section, and replace `<local-table-name>` with a name for the table.

In the PySpark shell, run SQL statements using `spark.sql()`. The PySpark shell runs Python, so if you enter a SQL statement directly, it fails with `SyntaxError: invalid syntax`.

```python
spark.sql("""
  CREATE TABLE <local-table-name>
  USING deltaSharing
  LOCATION '<profile-path>#<share-name>.<schema-name>.<table-name>'
""")

spark.sql("SELECT * FROM <local-table-name> LIMIT 10").show()
```

### Access shared change data feed using Spark

If the table history has been shared with you and change data feed (CDF) is enabled on the source table, access the change data feed by running the following, replacing these variables. Requires `delta-sharing-spark` 0.5.0 or above.

One start parameter must be provided.

* `<profile-path>`: the location of the credential file.
* `<share-name>`: the value of `share=` for the table.
* `<schema-name>`: the value of `schema=` for the table.
* `<table-name>`: the value of `name=` for the table.
* `<starting-version>`: optional. The starting version of the query, inclusive. Specify as a Long.
* `<ending-version>`: optional. The ending version of the query, inclusive. If the ending version is not provided, the API uses the latest table version.
* `<starting-timestamp>`: optional. The starting timestamp of the query, this is converted to a version created greater or equal to this timestamp. Specify as a string in the format `yyyy-mm-dd hh:mm:ss[.fffffffff]`.
* `<ending-timestamp>`: optional. The ending timestamp of the query, this is converted to a version created earlier or equal to this timestamp. Specify as a string in the format `yyyy-mm-dd hh:mm:ss[.fffffffff]`

#### Python

```python
delta_sharing.load_table_changes_as_spark(f"<profile-path>#<share-name>.<schema-name>.<table-name>",
  starting_version=<starting-version>,
  ending_version=<ending-version>)

delta_sharing.load_table_changes_as_spark(f"<profile-path>#<share-name>.<schema-name>.<table-name>",
  starting_timestamp=<starting-timestamp>,
  ending_timestamp=<ending-timestamp>)

spark.read.format("deltaSharing").option("readChangeFeed", "true")\
.option("startingVersion", <starting-version>)\
.option("endingVersion", <ending-version>)\
.load("<profile-path>#<share-name>.<schema-name>.<table-name>")

spark.read.format("deltaSharing").option("readChangeFeed", "true")\
.option("startingTimestamp", <starting-timestamp>)\
.option("endingTimestamp", <ending-timestamp>)\
.load("<profile-path>#<share-name>.<schema-name>.<table-name>")
```

#### Scala

```scala
spark.read.format("deltaSharing").option("readChangeFeed", "true")
.option("startingVersion", <starting-version>)
.option("endingVersion", <ending-version>)
.load("<profile-path>#<share-name>.<schema-name>.<table-name>")

spark.read.format("deltaSharing").option("readChangeFeed", "true")
.option("startingTimestamp", <starting-timestamp>)
.option("endingTimestamp", <ending-timestamp>)
.load("<profile-path>#<share-name>.<schema-name>.<table-name>")
```

If the output is empty or doesn't contain the data you expect, contact the data provider.

### <a id="streaming-source" />Access a shared table using Spark Structured Streaming

If the table history is shared with you, you can stream read the shared data. Requires `delta-sharing-spark` 0.6.0 or above.

Supported options:

* `ignoreDeletes`: Ignore transactions that delete data.
* `ignoreChanges`: Re-process updates if files were rewritten in the source table due to a data changing operation such as `UPDATE`, `MERGE INTO`, `DELETE` (within partitions), or `OVERWRITE`. Unchanged rows can still be emitted. Therefore, your downstream consumers should be able to handle duplicates. Deletes are not propagated downstream. `ignoreChanges` subsumes `ignoreDeletes`. Therefore, if you use `ignoreChanges`, your stream is not disrupted by either deletions or updates to the source table.
* `startingVersion`: The shared table version to start from. All table changes starting from this version (inclusive) are read by the streaming source.
* `startingTimestamp`: The timestamp to start from. All table changes committed at or after the timestamp (inclusive) are read by the streaming source. Example: `"2023-01-01 00:00:00.0"`.
* `maxFilesPerTrigger`: The number of new files to be considered in every micro-batch.
* `maxBytesPerTrigger`: The amount of data that gets processed in each micro-batch. This option sets a “soft max”, meaning that a batch processes approximately this amount of data and may process more than the limit in order to make the streaming query move forward in cases when the smallest input unit is larger than this limit.
* `readChangeFeed`: Stream read the change data feed of the shared table.

Supported triggers:

* `Trigger.ProcessingTime`: The default trigger, used when no explicit trigger is specified. Data is processed in continuous micro-batches.
* `Trigger.AvailableNow`: The query captures the shared table's server-side version at start, processes the backlog as multiple micro-batches that honor `maxFilesPerTrigger` and `maxVersionsPerRpc`, and terminates when the captured version is exhausted. Requires `delta-sharing-spark` 1.4.0 or above. Older versions fall back to a `Trigger.AvailableNow` wrapper that does not respect `maxVersionsPerRpc`.
* `Trigger.Once`: Deprecated; use `Trigger.AvailableNow` instead. With `delta-sharing-spark` versions below 1.4.0, `Trigger.AvailableNow` falls back to a wrapper that does not respect `maxVersionsPerRpc`.

#### Sample Structured Streaming queries

##### Python

```python
spark.readStream.format("deltaSharing")\
.option("startingVersion", 0)\
.option("ignoreDeletes", true)\
.option("maxBytesPerTrigger", 10000)\
.load("<profile-path>#<share-name>.<schema-name>.<table-name>")
```

##### Scala

```scala
spark.readStream.format("deltaSharing")
.option("startingVersion", 0)
.option("ignoreChanges", true)
.option("maxFilesPerTrigger", 10)
.load("<profile-path>#<share-name>.<schema-name>.<table-name>")
```

See also [Structured Streaming concepts](https://docs.databricks.com/aws/en/structured-streaming/concepts.md).

### <a id="deletion-vectors" />Read tables with deletion vectors or column mapping enabled

Deletion vectors are a storage optimization feature that your provider can enable on shared Delta tables. See [Deletion vectors in Databricks](https://docs.databricks.com/aws/en/tables/features/deletion-vectors.md).

Databricks also supports column mapping for Delta tables. See [Rename and drop columns with Delta Lake column mapping](https://docs.databricks.com/aws/en/tables/features/column-mapping.md).

If your provider shared a table with deletion vectors or column mapping enabled, you can read the table using compute that is running `delta-sharing-spark` 3.1 or above. If you are using Databricks clusters, you can perform batch reads using a cluster running Databricks Runtime 14.1 or above. CDF and streaming queries require Databricks Runtime 14.2 or above.

You can perform batch queries as-is, because they can automatically resolve `responseFormat` based on the table features of the shared table.

To read a change data feed (CDF) or to perform streaming queries on shared tables with deletion vectors or column mapping enabled, you must set the additional option `responseFormat=delta`. The following example also configures the Delta Lake SQL extension and catalog. If you use the PySpark shell or `spark-shell`, set these options when you start the shell instead, because they can't be changed after the shell creates its Spark session. See [Install the OpenSharing Python and Spark connectors](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#install-spark-connectors).

The following examples show batch, CDF, and streaming queries:

```scala
import org.apache.spark.sql.SparkSession

val spark = SparkSession
        .builder()
        .appName("...")
        .master("...")
        .config("spark.sql.extensions", "io.delta.sql.DeltaSparkSessionExtension")
        .config("spark.sql.catalog.spark_catalog", "org.apache.spark.sql.delta.catalog.DeltaCatalog")
        .getOrCreate()

val tablePath = "<profile-file-path>#<share-name>.<schema-name>.<table-name>"

// Batch query
spark.read.format("deltaSharing").load(tablePath)

// CDF query
spark.read.format("deltaSharing")
  .option("readChangeFeed", "true")
  .option("responseFormat", "delta")
  .option("startingVersion", 1)
  .load(tablePath)

// Streaming query
spark.readStream.format("deltaSharing").option("responseFormat", "delta").load(tablePath)
```

### <a id="row-tracking" />Read row tracking columns in shared tables

If the data provider has enabled row tracking on a shared table, you can query the row tracking metadata columns using Scala Spark. See [Row tracking in Databricks](https://docs.databricks.com/aws/en/tables/features/row-tracking.md) for a list of available columns.

You must set the `responseFormat` option to `delta`.

```scala
spark.read.format("deltaSharing")
  .option("responseFormat", "delta")
  .load("<profile-path>#<share-name>.<schema-name>.<table-name>")
  .select("_metadata.row_id")
  .show()
```

> [!NOTE]
>
> Only the delta response format is supported for querying row tracking columns in the Spark client. Dump connectors are not supported.

## <a id="pandas" />Pandas: Read shared data

Follow these steps to access shared data in `pandas` 0.25.3 or above.

These instructions assume that you have access to the credential file that was shared by the data provider. See [Get access in the Databricks-to-Open sharing model](https://docs.databricks.com/aws/en/opensharing/recipient.md#get-access-open).

> [!NOTE]
>
> If you are using `pandas` on a Databricks workspace that is enabled for Unity Catalog, and you used the import provider UI to import the provider and share, the instructions in this section do not apply to you. You can access shared tables just as you would any other table that is registered in Unity Catalog. You do not need to install the `delta-sharing` Python connector or provide the path to the credential file. See [Import a provider and read shared data in Databricks](https://docs.databricks.com/aws/en/opensharing/read-data-open-databricks.md).

### Install the OpenSharing Python connector

To access metadata related to the shared data, such as the list of tables shared with you, you must install the [delta-sharing Python connector](https://delta.io/connectors/). For information about Python connector limitations, see [ OpenSharing Python connector limitations](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#python-limitations).

```bash
pip install delta-sharing
```

### <a id="python-connector-version" />Python version requirements

The latest OpenSharing Python connector requires Python 3.10 or above. On an earlier version of Python, `pip` doesn't return an error. Instead, it installs an older release of the Python connector that might not support the features described on this page. To check which release is installed, run the following command:

```bash
pip show delta-sharing
```

### List shared tables using `pandas`

To list the tables in the share, run the following, replacing `<profile-path>/config.share` with the location of the credential file.

```python
import delta_sharing

client = delta_sharing.SharingClient(f"<profile-path>/config.share")

client.list_all_tables()
```

If the output is empty or doesn't contain the tables you expect, contact the data provider.

### Access shared data using `pandas`

To access shared data in `pandas` using Python, run the following, replacing the variables as follows:

* `<profile-path>`: the location of the credential file.
* `<share-name>`: the value of `share=` for the table.
* `<schema-name>`: the value of `schema=` for the table.
* `<table-name>`: the value of `name=` for the table.

```python
import delta_sharing
delta_sharing.load_as_pandas(f"<profile-path>#<share-name>.<schema-name>.<table-name>")
```

### Access a shared change data feed using `pandas`

To access the change data feed for a shared table in `pandas` using Python run the following, replacing the variables as follows. A change data feed may not be available, depending on whether or not the data provider shared the change data feed for the table.

* `<starting-version>`: optional. The starting version of the query, inclusive.
* `<ending-version>`: optional. The ending version of the query, inclusive.
* `<starting-timestamp>`: optional. The starting timestamp of the query. This is converted to a version created greater or equal to this timestamp.
* `<ending-timestamp>`: optional. The ending timestamp of the query. This is converted to a version created earlier or equal to this timestamp.

```python
import delta_sharing
delta_sharing.load_table_changes_as_pandas(
  f"<profile-path>#<share-name>.<schema-name>.<table-name>",
  starting_version=<starting-version>,
  ending_version=<ending-version>)

delta_sharing.load_table_changes_as_pandas(
  f"<profile-path>#<share-name>.<schema-name>.<table-name>",
  starting_timestamp=<starting-timestamp>,
  ending_timestamp=<ending-timestamp>)
```

If the output is empty or doesn't contain the data you expect, contact the data provider.

## <a id="power-bi" />Power BI: Read shared data

The Power BI OpenSharing connector allows you to discover, analyze, and visualize datasets shared with you through the OpenSharing open protocol.

### Requirements

* Power BI Desktop 2.99.621.0 or above.
* Access to the credential file that was shared by the data provider. See [Get access in the Databricks-to-Open sharing model](https://docs.databricks.com/aws/en/opensharing/recipient.md#get-access-open).

### Connect to Databricks

To connect to Databricks using the OpenSharing connector, do the following:

1. Open the shared credential file with a text editor to retrieve the endpoint URL and the token.
2. Open Power BI Desktop.
3. On the **Get Data** menu, search for **OpenSharing**.
4. Select the connector and click **Connect**.
5. Enter the endpoint URL that you copied from the credentials file into the **OpenSharing Server URL** field.
6. Optionally, in the **Advanced Options** tab, set a **Row Limit** for the maximum number of rows that you can download. This is set to 1 million rows by default.
7. Click **OK**.
8. For **Authentication**, copy the token that you retrieved from the credentials file into **Bearer Token**.
9. Click **Connect**.

### Limitations of the Power BI OpenSharing connector

The Power BI OpenSharing Connector has the following limitations:

* The data that the connector loads must fit into the memory of your machine. To manage this requirement, the connector limits the number of imported rows to the **Row Limit** that you set under the Advanced Options tab in Power BI Desktop.

## <a id="tableau" />Tableau: Read shared data

The Tableau OpenSharing connector allows you to discover, analyze, and visualize datasets that are shared with you through the OpenSharing open protocol.

> [!WARNING]
>
> Tableau is deprecating the OpenSharing connector on [Tableau Exchange](https://exchange.tableau.com/products/1019). If the connector fails to load, Tableau shows a generic username and password prompt instead of the **Upload Share file** option. To read shared data, use a supported client instead, such as [Power BI](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#power-bi), [Pandas](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#pandas), or [Apache Spark](https://docs.databricks.com/aws/en/opensharing/read-data-open.md#apache-spark). If you have a Unity Catalog-enabled Databricks workspace, ask the provider to share the data with you using [Databricks-to-Databricks sharing](https://docs.databricks.com/aws/en/opensharing/read-data-databricks.md).

### Requirements

* Tableau Desktop and Tableau Server 2024.1 or above
* Access to the credential file that was shared by the data provider. See [Get access in the Databricks-to-Open sharing model](https://docs.databricks.com/aws/en/opensharing/recipient.md#get-access-open).

### Connect to Databricks

To connect to Databricks using the OpenSharing connector, do the following:

1. Go to [Tableau Exchange](https://exchange.tableau.com/products/1019), follow the instructions to download the OpenSharing Connector, and put it in an appropriate desktop folder.
2. Open Tableau Desktop.
3. On the **Connectors** page, search for “OpenSharing by Databricks”.
4. Select **Upload Share file**, and choose the credential file that was shared by the provider.
5. Click **Get Data**.
6. In the Data Explorer, select the table.
7. Optionally add SQL filters or row limits.
8. Click **Get Table Data**.

### <a id="tableau-limitations" />Limitations

The Tableau OpenSharing Connector has the following limitations:

* The data that the connector loads must fit into the memory of your machine. To manage this requirement, the connector limits the number of imported rows to the row limit that you set in Tableau.
* All columns are returned as type `String`.
* SQL Filter only works if your OpenSharing server supports [predicateHint](https://github.com/delta-io/delta-sharing/blob/main/PROTOCOL.md#request-body).
* Deletion vectors are not supported.
* Column mapping is not supported.

## <a id="python-limitations" /> OpenSharing Python connector limitations

These limitations are specific to the OpenSharing Python connector:

* The OpenSharing Python connector 1.1.0+ supports snapshot queries on tables with column mapping but CDF queries on tables with column mapping are not supported.
* The OpenSharing Python connector fails CDF queries with `use_delta_format=True` if the schema changed during the queried version range.

## <a id="streaming-table-limitations" />Streaming table limitations

You can only read the current snapshot of a shared streaming table. The following features are not supported for streaming tables in Databricks-to-Open sharing:

* Querying the table's history data
* Querying the table's change data feed (CDF)
* Using the table as a source for Spark Structured Streaming

## <a id="materialized-view-limitations" />Materialized view limitations

You can only read the current snapshot of a shared materialized view. Using a materialized view as a source for Spark Structured Streaming is not supported in Databricks-to-Open sharing.

## Request a new credential

If your credential activation URL or downloaded credential is lost, corrupted, or compromised, or your credential expires without your provider sending you a new one, contact your provider to request a new credential.

If you're a Databricks recipient who imported the credential as a provider object in Unity Catalog, apply the new credential using the Databricks REST API. See [Rotate credentials for open recipients](https://docs.databricks.com/aws/en/opensharing/manage-provider.md#rotate-credentials).
