Skip to main content

Python client for the pd4castr API

Project description

pdView logo

pd4castr API SDK

Official Python client for the pd4castr API

InstallationQuick StartUsageAPI Reference


Installation

Requires Python >= 3.8

pip install pd4castr-api-sdk

Quick Start

Authenticate using your pd4castr API credentials:

from pd4castr_api_sdk import Client

client = Client(
    client_id="my-client-id",
    client_secret="my-client-secret",
)

models = client.get_models()
print(f"Found {len(models)} models")

client.close()

Context Manager

The client implements context manager protocol for automatic cleanup:

with Client(
    client_id="my-client-id",
    client_secret="my-client-secret",
) as client:
    models = client.get_models()

Usage

List all Models

Reference: Client.getModels

Retrieve all available models, optionally filtered by time horizon.

# Get all models
models = client.get_models()

# Filter by time horizon
models = client.get_models(time_horizon="day_ahead")

Get a Model

Reference: Client.get_model

Retrieve detailed information for a specific model.

model = client.get_model("model-id")
print(f"Model: {model.displayName}")

Get Current User

Reference: Client.get_current_user

Retrieve information about the currently authenticated user.

user = client.get_current_user()
print(f"User: {user.email}")
if user.organisation:
    print(f"Organisation: {user.organisation.displayName}")

Error Handling

Reference: Exceptions

Handle common error cases with typed exceptions.

from pd4castr_api_sdk import NotFoundError, ApiError

try:
    model = client.get_model("invalid-id")
except NotFoundError:
    print("Model not found")
except ApiError as e:
    print(f"API error {e.status_code}: {e.message}")

API Reference

Client:

Types:

  • Model - Model information and related types
  • User - User information and related types

Exceptions:

Client

Client(
    client_id: str,
    client_secret: str,
    timeout: float = 30.0,
)

Main client class for interacting with the pd4castr API. Supports context manager protocol for automatic cleanup.

Configuration:

  • client_id - OAuth client ID for authentication
  • client_secret - OAuth client secret for authentication
  • timeout - Request timeout in seconds (default: 30.0)

Client#getModels

List all models with optional time horizon filter.

Client#getModels(*, time_horizon: str | None = None) -> list[Model]

Parameters:

  • time_horizon (optional) - Filter models by time horizon:
    • day_ahead
    • week_ahead
    • quarterly
    • historical

Returns: A list of Model instances


Client#getModel

Get a specific model by ID.

Client#get_model(model_id: str) ->Model

Parameters:

  • model_id - Unique model identifier

Returns: Model instance

Raises:


Client#getCurrentUser

Get the currently authenticated user.

Client#get_current_user() ->User

Returns: User instance


Types

All types are implemented as pydantic models.

Model

class Model(BaseModel):
    id: str
    modelGroupId: str
    name: str
    displayName: str
    displayTimezone: str
    revision: int
    dockerImage: str
    notes: str
    createdAt: str
    horizon: TimeHorizon
    modelMetadata: ModelMetadata
    outputSpecification: list[ColumnSpecification]
    tags: list[str]
    sensitivities: list[SensitivitySpecification]
    outputFileFormat: FileFormat
    forecastVariable: ForecastVariableSpecification

class TimeHorizon(BaseModel):
    name: str
    shortName: str
    key: str

class ModelMetadata(BaseModel):
    description: str | None
    releaseDate: str | None
    resolution: str | None
    baseComparisonModel: str | None

class ColumnSpecification(BaseModel):
    name: str
    type: str
    ui: UISpecification | None

class UISpecification(BaseModel):
    seriesKey: bool | None
    colours: list[str] | None

class SensitivitySpecification(BaseModel):
    name: str
    categories: list[str]

class ForecastVariableSpecification(BaseModel):
    name: str
    shortName: str
    key: str

class FileFormat(Enum):
    json = "json"
    csv = "csv"
    parquet = "parquet"

User

class User(BaseModel):
    id: str
    email: str
    organisation: Organisation | None

class Organisation(BaseModel):
    id: str
    displayName: str
    slug: str
    domains: list[str]
    permissions: list[str]

Exceptions

ApiError

Base exception for API errors.

class ApiError(Exception):
    status_code: int
    message: str
    body: dict | None

NotFoundError

Resource not found error (HTTP 404). Inherits from ApiError.

class NotFoundError(ApiError):
    pass

Contributing

See CONTRIBUTING.md for development setup, testing, and contribution guidelines.

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

pd4castr_api_sdk-1.0.0.tar.gz (36.4 kB view details)

Uploaded Source

Built Distribution

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

pd4castr_api_sdk-1.0.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file pd4castr_api_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: pd4castr_api_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 36.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pd4castr_api_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f7df7b1bbaab4a7cf26a4dca0497f60ce06e2f377407c7371474bf6f9d187203
MD5 e14d678517b39623f90173ab7b021547
BLAKE2b-256 a07676bbff2193fed9c3bb4c3986bb805a5c74423576636fb034e33aab79f585

See more details on using hashes here.

Provenance

The following attestation bundles were made for pd4castr_api_sdk-1.0.0.tar.gz:

Publisher: main-deploy-prod.yml on pipelabs/pd4castr

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

File details

Details for the file pd4castr_api_sdk-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pd4castr_api_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78766d115fe5234b6d13551e776721abbfc302e606f9a01d1428a36cf9df43fd
MD5 044892818a6b1cff6af995d86f962120
BLAKE2b-256 a312b483c9484dfeb1e0d1f0e2428f46d4e39423489c1d7211dcd10f304749fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for pd4castr_api_sdk-1.0.0-py3-none-any.whl:

Publisher: main-deploy-prod.yml on pipelabs/pd4castr

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