Skip to main content

Python client for OSDU services

Project description

OSDU Python Client

SCM Compliance

Python client library for OSDU services, automatically generated from OpenAPI specifications and wrapped with a handwritten facade that handles authentication, retries, partition headers, and ergonomic per-operation calls.

Installation

pip install osdu-python-client

The base install supports Community/baremetal (Keycloak client credentials) and AWS (OAuth2 client credentials) — both use only httpx which is already a core dependency. For other cloud providers, install the matching extra:

Cloud Extra Command
Azure / Entra ID azure pip install 'osdu-python-client[azure]'
GCP gcp pip install 'osdu-python-client[gcp]'
IBM ibm pip install 'osdu-python-client[ibm]'
All providers all-csp pip install 'osdu-python-client[all-csp]'

Python 3.13+ is required.

Quick Start

from osdu_python_client import OsduClient
from osdu_python_client.generated.search.models.query_request import QueryRequest

with OsduClient() as osdu:  # config loaded from .env
    dto = osdu.search.query_records(
        body=QueryRequest(kind="osdu:wks:master-data--Wellbore:*", query="*", limit=1)
    )
    for record in dto.results:
        print(record.additional_properties)

Each osdu.<service>.<operation>(...) call auto-binds the underlying client and data-partition-id, returns the parsed response model on 2xx, and raises OsduError on non-2xx. Call .detailed(...) on any operation to get the full Response envelope (status code, headers, parsed error model).

Available Services

Attribute Service
crs_catalog CRS Catalog
crs_conversion CRS Conversion
dataset Dataset
entitlements Entitlements
file File
indexer Indexer
workflow Ingestion Workflow Service
legal Legal
notification Notification
partition Partition
policy Policy
register Register
schema Schema
search Search
seismic_ddms Seismic DDMS
storage Storage
unit Unit
wellbore_ddms Wellbore DDMS

Configuration

Configuration is loaded from environment variables or a .env file:

SERVER=https://your-osdu-instance.com
DATA_PARTITION_ID=your-partition
AUTH_PROVIDER=azure_msal
CLIENT_ID=...
AUTHORITY=https://login.microsoftonline.com/<tenant>
SCOPES=.../.default
AUTH_MODE=interactive   # interactive | device_flow | client_credentials | workload_identity

Auth Providers

Auth is pluggable via AUTH_PROVIDER. Azure MSAL is built in; other CSPs can be passed directly.

Provider Status Required config
azure_msal built-in CLIENT_ID, AUTHORITY, SCOPES, AUTH_MODE
aws_cognito stub bring your own TokenProvider
gcp_iam stub bring your own TokenProvider
ibm_iam stub bring your own TokenProvider

Azure MSAL flows

AUTH_MODE When to use Required config
interactive Local dev / tests client_id, authority, scopes
device_flow Headless scripts client_id, authority, scopes
client_credentials CI, service-to-service + client_secret
workload_identity AKS / Workload Identity Federation scopes; optional azure_client_id, azure_tenant_id, azure_federated_token_file

Tokens are cached to .msal_token_cache.bin (override with MSAL_CACHE_PATH). The transport retries 401 once with force_refresh=True and retries 429/502/503/504 with exponential backoff honouring Retry-After.

For workload_identity the token is cached in memory because there a writeable file system may not be available. The optional parameters are typically set by the Kubernetes runtime.

Custom / bring-your-own provider

Implement the TokenProvider protocol (one method) and pass it directly:

class MyAwsProvider:
    def get_token(self, force_refresh: bool = False) -> str:
        return "..."  # return a bearer token string

osdu = OsduClient(token_provider=MyAwsProvider())

Async

import asyncio
from osdu_python_client import AsyncOsduClient
from osdu_python_client.generated.search.models.query_request import QueryRequest

async def main():
    async with AsyncOsduClient() as osdu:
        dto = await osdu.search.query_records(
            body=QueryRequest(kind="osdu:wks:master-data--Wellbore:*", query="*", limit=1)
        )
        return dto.results

asyncio.run(main())

Per-service Header Overrides

# Scope extra headers to one service
with osdu.with_headers(service="crs_conversion", **{"frame-of-reference": "units=SI"}):
    osdu.crs_conversion.convert_records(body=req)

# Or apply to all services (e.g. correlation IDs)
with osdu.with_headers(**{"x-correlation-id": correlation_id}):
    ...

The async client exposes the same helper as async with osdu.with_headers(...).

Debugging

from osdu_python_client import enable_debug_logging
enable_debug_logging()                    # transport + auth at DEBUG
enable_debug_logging(include_bodies=True) # also log truncated request/response bodies

Authorization and Cookie headers are always redacted from log output. Bodies are off by default because OSDU payloads may contain PII.

Low-level: Raw Generated Client

The generated clients can be used directly with a static token when you need full control:

from osdu_python_client.generated.entitlements.api.list_group_on_behalf_of_api import (
    list_all_partition_groups,
)
from osdu_python_client.generated.entitlements.client import AuthenticatedClient

client = AuthenticatedClient(
    base_url="https://your-osdu-instance.com/api/entitlements/v2",
    token="YOUR_ACCESS_TOKEN",
)

result = list_all_partition_groups.sync_detailed(
    client=client,
    data_partition_id="your-partition-id",
    type_="NONE",
)
if result.parsed:
    for group in result.parsed.groups:
        print(group.name, group.email)

The async variant is asyncio_detailed(...).

Development

git clone https://community.opengroup.org/osdu/platform/system/sdks/osdu-python-client.git
cd osdu-python-client
uv sync --all-extras
uv run python generate_all.py
uv run pytest tests/test_facade.py tests/test_transport.py -q

For adding services, updating OpenAPI specs, the release process, and project structure, see docs/development.md.

License

Ref. License Information

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

osdu_python_client-0.4.1.tar.gz (476.5 kB view details)

Uploaded Source

Built Distribution

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

osdu_python_client-0.4.1-py3-none-any.whl (1.4 MB view details)

Uploaded Python 3

File details

Details for the file osdu_python_client-0.4.1.tar.gz.

File metadata

  • Download URL: osdu_python_client-0.4.1.tar.gz
  • Upload date:
  • Size: 476.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for osdu_python_client-0.4.1.tar.gz
Algorithm Hash digest
SHA256 6b75d37600021c20dd62893740b96e74c748cfffcf8c62a3c22924c524359301
MD5 3ef41445c1558fd3a80572ad2669aa66
BLAKE2b-256 87fefd3b325b88f244550db1929aa60e3fe419d626c6b3e961dfebcc0931c894

See more details on using hashes here.

File details

Details for the file osdu_python_client-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: osdu_python_client-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for osdu_python_client-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 32cc0cd971d52b0711a1c496417e76f1b23a4b09a457c0e92d21e6b80b4036d4
MD5 0cf0e079ff3a1a5dd9c2852cb82f253d
BLAKE2b-256 ed715845b54f4be92aac594b0c40e687875ac4e8bcb376c101bd1909ef2a1d1d

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