Metadata-Version: 2.4
Name: Datasphere-API
Version: 0.3.0
Summary: Asynchronous client for the internal SAP Datasphere API.
Project-URL: Homepage, https://github.com/peterschwps/SAP-Datasphere-API
Project-URL: Repository, https://github.com/peterschwps/SAP-Datasphere-API
Project-URL: Issues, https://github.com/peterschwps/SAP-Datasphere-API/issues
Author: Peter Schwips
License-Expression: MIT
License-File: LICENSE
Keywords: API,Async,Automation,Client,Datasphere,SAP
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Requires-Python: >=3.12
Requires-Dist: httpx>=0.28.1
Requires-Dist: playwright>=1.54.0
Description-Content-Type: text/markdown

# SAP-Datasphere-API

[![PyPI](https://img.shields.io/pypi/v/Datasphere-API?label=PyPI)](https://pypi.org/project/Datasphere-API/)
[![Python](https://img.shields.io/pypi/pyversions/Datasphere-API?label=Python)](https://pypi.org/project/Datasphere-API/)
[![CI](https://github.com/peterschwps/SAP-Datasphere-API/actions/workflows/ci.yml/badge.svg)](https://github.com/peterschwps/SAP-Datasphere-API/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

Asynchronous client for the internal SAP Datasphere API. This library powers the
[SAP-Datasphere-CLI](https://github.com/peterschwps/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.

<details>
  <summary><b>Analytical Models</b></summary>
  <ul>
    <li>get all analytical models</li>
    <li>get all analytical models by space</li>
    <li>get mapping of all analytical models and their views</li>
  </ul>
</details>

<details>
  <summary><b>Remote Tables</b></summary>
  <ul>
    <li>get all remote tables</li>
    <li>create statistics</li>
    <li>change statistics type</li>
    <li>refresh existing statistics</li>
  </ul>
</details>

<details>
  <summary><b>Task Chains</b></summary>
  <ul>
    <li>start a task chain without awaiting its result</li>
    <li>run a task chain and await its execution result</li>
    <li>retrieve task-chain run logs by log ID</li>
  </ul>
</details>

<details>
  <summary><b>Views</b></summary>
  <ul>
    <li>get all views</li>
    <li>get all attributes of a view</li>
    <li>get all partitions</li>
    <li>create partitions</li>
    <li>lock partitions</li>
    <li>unlock partitions</li>
    <li>delete partitions</li>
    <li>check whether a view is persisted</li>
    <li>create persistence (with/without awaiting the result)</li>
    <li>remove persistence (with/without awaiting the result)</li>
    <li>get all logs of a view</li>
    <li>get extended task logs</li>
    <li>analyze view using the view analyzer</li>
    <li>retrieve view analyzer results</li>
  </ul>
</details>

> [!NOTE]
> Open an issue if you need another functionality.

## Installation

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

The interactive login requires a Chrome or Edge installation.

## Quickstart

```python
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](https://github.com/peterschwps/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.
