Skip to main content

Python SDK for SAP Business Data Cloud

Project description

SAP Business Data Cloud SDK

Table of Contents

Introduction

With this SDK you can perform Business Data Cloud Connect operations such as:

  • Create or update shares
  • Create or update shares CSN
  • Publish or unpublish Data Products

Open Resource Discovery (ORD) is a protocol that allows applications and services to self-describe their resources and capabilities. It facilitates cross consumption of resources and capabilities between different systems through a common standard interface.

Delta Sharing (DS) is an open protocol for secure sharing of Delta tables. SAP Business Data Cloud support Delta Sharing and allows user data sets, represented as shares, to be shared securely.

This document focus on describing how SAP Business Data Cloud SDK should be used to publish shares and ORD Data Products for downstream consumption within SAP Business Data Cloud.

Installation

To install this SDK use the following pip command:

pip install sap-bdc-connect-sdk

Usage

Create a client

from bdc_connect_sdk.auth import BdcConnectClient
from bdc_connect_sdk.auth import DatabricksClient

databricks_client = DatabricksClient(dbutils, "<recipient-name>")
bdc_connect_client = BdcConnectClient(databricks_client)
  • DatabricksClient receives:
    • dbutils parameter, which is a Databricks utility that can be used inside the Databricks notebooks
    • recipient-name parameter, which is the recipient name representing the Business Data Cloud in which the Data Product should be published
  • BdcConnectClient receives:
    • DatabricksClient parameter to get information from the Databricks environment (e.g. secrets, api_token, workspace_url_base)

Create or update share

A share is a mechanism for distributing and accessing data across different systems. Creating or updating a share involves including specific attributes, such as @openResourceDiscoveryV1, in the request body, aligning with the Open Resource Discovery protocol. This procedure ensures that the share is properly structured and described according to specified standards, facilitating effective data sharing and management.

from bdc_connect_sdk.auth import BdcConnectClient
from bdc_connect_sdk.auth import DatabricksClient

bdc_connect_client = BdcConnectClient(DatabricksClient(dbutils, "<recipient-name>"))

share_name = "<share-name>"

open_resource_discovery_information = {
    "@openResourceDiscoveryV1": {
        "title": "<title>",
        "shortDescription": "<short-description>",
        "description": "<description>"
    }
}

response = bdc_connect_client.create_or_update_share(
    share_name,
    open_resource_discovery_information
)
print(f"[REQUEST] Create or update share request was executed and returned {response}")

Create or update share CSN

The CSN serves as a standardized format for configuring and describing shares within a network. To create or update the CSN for a share, it's advised to prepare the CSN content in a separate file and include this content in the request body. This approach ensures accuracy and compliance with the CSN interoperability specifications, facilitating consistent and effective share configuration across systems.

Note: The CSN schema, can be efficiently generated using a dedicated script generate_csn_template available in csn_generator file. This script automates the creation of CSN content for Databricks environments based on a Databricks share.

from bdc_connect_sdk.auth import BdcConnectClient
from bdc_connect_sdk.auth import DatabricksClient
from bdc_connect_sdk.utils import csn_generator

bdc_connect_client = BdcConnectClient(DatabricksClient(dbutils, "<recipient-name>"))

share_name = "<share-name>"

csn_schema = csn_generator.generate_csn_template(share_name)

response = bdc_connect_client.create_or_update_share_csn(
    share_name,
    csn_schema
)
print(f"[REQUEST] Create or update CSN request was executed and returned {response if response else 'OK'}")

If the generated CSN needs to be modified for any reason, it can be written to a file for editing, for example.

from bdc_connect_sdk.utils import csn_generator
import json

share_name = "<share-name>"
csn_schema = csn_generator.generate_csn_template(share_name)

file_path = f"csn_{share_name}.json"
with open(file_path, "w") as csn_file:
    csn_file.write(json.dumps(csn_schema, indent=2))

# change the file

with open(file_path, "r") as csn_file:
    changed_csn_schema = csn_file.read()

csn_schema = changed_csn_schema

Publish a Data Product

A Data Product is an abstraction that represents a type of data or data set within a system, facilitating easier management and sharing across different platforms. It bundles resources or API endpoints to enable efficient data access and utilization by integrated systems. Publishing a Data Product allows these systems to access and consume the data, ensuring seamless communication and resource sharing.

from bdc_connect_sdk.auth import BdcConnectClient
from bdc_connect_sdk.auth import DatabricksClient

bdc_connect_client = BdcConnectClient(DatabricksClient(dbutils, "<recipient-name>"))

share_name = "<share-name>"

response = bdc_connect_client.publish_data_product(
    share_name
)
print(f"[REQUEST] Publish Data Product request was executed and returned {response if response else 'OK'}")

Unpublish a Data Product

Unpublishing a Data Product involves withdrawing access to the data, typically when it has been sufficiently consumed or is no longer desired to be shared. This action helps maintain control over data accessibility and ensures that sharing aligns with security and usage policies. By unpublishing, the system can effectively manage the lifecycle of data and its availability to other integrated platforms.

from bdc_connect_sdk.auth import BdcConnectClient
from bdc_connect_sdk.auth import DatabricksClient

bdc_connect_client = BdcConnectClient(DatabricksClient(dbutils, "<recipient-name>"))

share_name = "<share-name>"

response = bdc_connect_client.delete_share(
    share_name
)
print(f"[REQUEST] Delete share request was executed and returned {response if response else 'OK'}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sap_bdc_connect_sdk-1.1.15-py3-none-any.whl (48.2 kB view details)

Uploaded Python 3

File details

Details for the file sap_bdc_connect_sdk-1.1.15-py3-none-any.whl.

File metadata

File hashes

Hashes for sap_bdc_connect_sdk-1.1.15-py3-none-any.whl
Algorithm Hash digest
SHA256 082cf2a7c51478791a420134fb550b8393d5b1db97d0cda62fcd4de7bdc898f8
MD5 3e2d58af14de0d4c2a5e1df35f85d31e
BLAKE2b-256 75996b43a6d85dd5e645a7ffb1e7bf705c982240a1831243d7c6f6e939430c1b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page