Skip to main content

Unofficial async Python client for the SAP Datasphere automation APIs.

Project description

Datasphere-API

Unofficial async Python client for the SAP Datasphere automation APIs. This library powers the SAP-Datasphere-CLI and can be used to build your own automations (e.g. MCP servers or scheduled jobs).

[!NOTE] 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.

Features

  • Views: export view analytics (persistence candidates), search views by attribute, persist/unpersist views, create/remove partitions, lock/unlock partitions.
  • Remote Tables: list tables with statistics information, create/update statistics (Record Count / Simple / Histogram), refresh statistics.
  • Task Chains: run task chains and wait for their completion.
  • Analytical Models: export models with all their views (optionally per space), measure view persistence runtimes.
  • OAuth login included: interactive authorization code flow via a real Chrome/Edge window (Playwright) with automatic token refresh and a shared token cache.

Installation

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

The interactive login drives an installed Chrome or Edge browser via Playwright channels — a regular Chrome/Edge installation is required, no playwright install download is needed.

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()
        results = await client.task_chains.run(
            chains=[{"entity": "MY_CHAIN", "space": "MY_SPACE"}],
        )
        print(results)
    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

client.login() first tries to refresh cached tokens from the token store (session.json in the user data directory of Datasphere). If no tokens are cached or the refresh fails, a browser window opens for the interactive login. All consumers of this library share the same token cache, so a login in one tool also benefits the others.

Layered results

The library returns data on two levels:

  • Curated results (recommended): high-level operations like views.persist_views() or remote_tables.create_statistics() return small, typed result structures (see datasphere_api.models). Their keys intentionally match the CSV/JSON exports of the CLI.
  • Raw payloads: low-level fetchers like views.get_all_views() or remote_tables.get_all_tables() return the parsed API payload, typed with broad TypedDicts. For anything not covered, client.session is the authenticated httpx.AsyncClient — you can call any endpoint directly.

Long-running batch operations accept an on_result/on_update callback that is invoked after every finished item, so consumers can save intermediate results during runs that take hours.

Development

uv sync
uv run pytest
uv run ruff check .
uv run pyright

License

MIT

Project details


Download files

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

Source Distribution

datasphere_api-0.1.0.tar.gz (50.4 kB view details)

Uploaded Source

Built Distribution

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

datasphere_api-0.1.0-py3-none-any.whl (29.6 kB view details)

Uploaded Python 3

File details

Details for the file datasphere_api-0.1.0.tar.gz.

File metadata

  • Download URL: datasphere_api-0.1.0.tar.gz
  • Upload date:
  • Size: 50.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for datasphere_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 39402735a51ee5e8c83b9c5a467b6f28b029f93d1a4b7d3b90961ba81bda5d00
MD5 b2102d3823aa60b32ec6f7c216345eab
BLAKE2b-256 0769209eec5ba23854507884e94bf23d355907dc195088d403d69242256f9b1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for datasphere_api-0.1.0.tar.gz:

Publisher: release.yml on peterschwps/SAP-Datasphere-API

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file datasphere_api-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: datasphere_api-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 29.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for datasphere_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f20ad71f166cf540016f33f6493d408edd78d96e3ef94d977d0f0c0687adc8cb
MD5 7656fa1c5aa12a5be2d63851ddaeb4ff
BLAKE2b-256 95186863ccd73b0bd1dda1084666a88045dfa54887c781c701d8232c897be0b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for datasphere_api-0.1.0-py3-none-any.whl:

Publisher: release.yml on peterschwps/SAP-Datasphere-API

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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