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-0.0.0.tar.gz (36.5 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-0.0.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pd4castr_api_sdk-0.0.0.tar.gz
  • Upload date:
  • Size: 36.5 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-0.0.0.tar.gz
Algorithm Hash digest
SHA256 415dc25f3a9c4a5943a33e5eb0e4bc4049579a03da56e3e68984ecca60b8fddd
MD5 6222fd75aa64bc6d225a850cc9f94c47
BLAKE2b-256 ba2c6fe7a784f06b9d4af05979289b33e244e2ac96f763a3973359adae9879c3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pd4castr_api_sdk-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2c16661e2c6b6c101444d56db99552fda1fee4f65382c8b39724609abf35cb6
MD5 531645c00b77218c542220b21be5fda8
BLAKE2b-256 1bd8a8fa8c34043ab20e7578a2544ad076d116fb8d352351edc85cbcb3035955

See more details on using hashes here.

Provenance

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