Skip to content

peterschwps/SAP-Datasphere-API

Repository files navigation

SAP-Datasphere-API

PyPI Python CI License: MIT

Asynchronous client for the internal SAP Datasphere API. This library powers the SAP-Datasphere-CLI and can be used to build your own automations.

Features

Datasphere Features

Extend the sections for a list of all supported features.

Analytical Models
  • get all analytical models
  • get all analytical models by space
  • get mapping of all analytical models and their views
Remote Tables
  • get all remote tables
  • create statistics
  • change statistics type
  • refresh existing statistics
Task Chains
  • start a task chain without awaiting its result
  • run a task chain and await its execution result
  • retrieve task-chain run logs by log ID
Views
  • get all views
  • get all attributes of a view
  • get all partitions
  • create partitions
  • lock partitions
  • unlock partitions
  • delete partitions
  • check whether a view is persisted
  • create persistence (with/without awaiting the result)
  • remove persistence (with/without awaiting the result)
  • get all logs of a view
  • get extended task logs
  • analyze view using the view analyzer
  • retrieve view analyzer results

Note

Open an issue if you need another functionality.

Installation

pip install datasphere-api
# or
uv add datasphere-api

The interactive login requires a Chrome or Edge installation.

Quickstart

import asyncio

from datasphere_api import DatasphereClient, DatasphereConfig


async def main() -> None:
    config = DatasphereConfig(
        base_url="https://example.eu10.hcs.cloud.sap",
        authorization_url="https://example.authentication.eu10.hana.ondemand.com/oauth/authorize",
        token_url="https://example.authentication.eu10.hana.ondemand.com/oauth/token",
        client_id="...",
        client_secret="...",
    )
    client = DatasphereClient(config)
    try:
        await client.login()
        success, log_details = await client.task_chains.run("MY_CHAIN", "MY_SPACE")
        print(success, log_details.get("runTime"))
    finally:
        await client.aclose()


asyncio.run(main())

The URLs and credentials can be found in your tenant under System > Administration (Tenant Links and App Integration). The OAuth client has to be of type "Interactive Usage" with the redirect URI http://localhost:8080.

Authentication

This client supports interactive and non-interactive authentication. If tokens with a refresh token are provided, it tries to refresh them first. If no valid tokens are available, it opens a browser window by default. Non-interactive applications (e.g. MCP servers) can disable this fallback with client.login(tokens, allow_interactive_fallback=False). After a valid session has been created, the client returns the tokens.

Make sure to store those tokens if you want to persist the session across multiple runs (see SAP-Datasphere-CLI for an example). The client itself does not persist any tokens!

Layered results

This library aims to provide a thin client for the internal Datasphere API. It works on two levels:

  • Endpoint methods: one method = one HTTP call, acting as an unofficial documentation of the internal Datasphere API (e.g. views.get_partitioning() or remote_tables.create_statistics()). They return the parsed payload or a small typed outcome.

  • Single-entity workflows: minimal compositions of endpoint calls that every consumer needs identically, mostly start-and-poll flows (which can be triggered by clicking a button in Datasphere) like views.persist_view(), views.analyze_view() or task_chains.run().

Both levels mirror single UI actions in SAP Datasphere, e.g. clicking a button or running a search query.

Disclaimer

This project is not affiliated with, endorsed by, or supported by SAP. It uses the same internal HTTP endpoints as the SAP Datasphere web UI, which may change without notice.

About

Asynchronous client for the internal SAP Datasphere API.

Topics

Resources

License

Stars

2 stars

Watchers

1 watching

Forks

Contributors

Languages