Python and pandas Open Sharing example

Use a downloaded external sharing profile to list shared tables and read an analytics table into a pandas DataFrame.

Before you start

  • You downloaded an external sharing profile for the Machine Data Lake analytics table.

  • Your Python environment can install and use a version of the Delta Sharing Python connector for Open Sharing.

  • You know the share name, schema name, and table name that the client must read.

Install the connector

Install the Delta Sharing Python connector in the Python environment that reads the shared table.

CODE
python -m pip install delta-sharing

For current Delta Sharing Python connector guidance, see Python Connector in the Delta Sharing repository.

List shared tables

Use the sharing profile to confirm which tables the client can see.

PYTHON
import delta_sharing

profile_file = r"C:\Users\<user>\.delta_sharing\profiles\mdl-open-sharing.share"
client = delta_sharing.SharingClient(profile_file)

tables = client.list_all_tables()
print(tables)

Read a table into pandas

Build the table URL by appending the fully qualified table name to the profile file path. The table URL format is <profile-file-path>#<share-name>.<schema-name>.<table-name>.

PYTHON
import delta_sharing

profile_file = r"C:\Users\<user>\.delta_sharing\profiles\mdl-open-sharing.share"
table_url = profile_file + "#<share_name>.<schema_name>.<table_name>"

df = delta_sharing.load_as_pandas(table_url)
print(df.head())

For the current Machine Data Lake sharing workflow, read the latest snapshot of the shared table. Do not depend on time travel, Change Data Feed, Delta table versions, or commit history unless Splunk documents support for those features.

For Delta Sharing read examples, see Read Delta Sharing Tables.

Troubleshooting checks

Symptom Check
The client returns an authentication or authorization error. Confirm that the profile was not revoked or expired. Download a new profile only when continued access is authorized.
The table is not listed or cannot be loaded. Confirm the share, schema, and table names. Also confirm that the analytics table is still shared with the profile that the client uses.
The returned columns do not match the expected workflow. Review the analytics table schema. If fields are missing, create a new analytics table promotion with the required fields.