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.1.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.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pd4castr_api_sdk-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 e706ef4c116559c177203d5ebf42361011769da92dd85b977d7f57a95375b734
MD5 826cad7e6a7468c7404413686e5dfb68
BLAKE2b-256 c7c6a26a763d5957ba9dc52142570b9a2a1c020cb050165b10b1ce361c51c91b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pd4castr_api_sdk-1.0.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pd4castr_api_sdk-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 48bf1227ca0437cfa43baec76b943ece45e459acdd1040bf5ac558985bb247d9
MD5 23f38706ce670f59c9e13718946e79c4
BLAKE2b-256 a54552ce011404394ac0f84f65fb7232d4b46546d464d45d117db3eedda36e0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pd4castr_api_sdk-1.0.1-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