Python client for the pd4castr API
Project description
pd4castr API SDK
Official Python client for the pd4castr API
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
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
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
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:
Client- Main API clientClient#getModels- List all modelsClient#getModel- Get a specific modelClient#getCurrentUser- Get the current user
Types:
Exceptions:
ApiError- Base API errorNotFoundError- Resource not found error
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 authenticationclient_secret- OAuth client secret for authenticationtimeout- 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_aheadweek_aheadquarterlyhistorical
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:
NotFoundErrorif model doesn't exist
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
415dc25f3a9c4a5943a33e5eb0e4bc4049579a03da56e3e68984ecca60b8fddd
|
|
| MD5 |
6222fd75aa64bc6d225a850cc9f94c47
|
|
| BLAKE2b-256 |
ba2c6fe7a784f06b9d4af05979289b33e244e2ac96f763a3973359adae9879c3
|
Provenance
The following attestation bundles were made for pd4castr_api_sdk-0.0.0.tar.gz:
Publisher:
main-deploy-prod.yml on pipelabs/pd4castr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pd4castr_api_sdk-0.0.0.tar.gz -
Subject digest:
415dc25f3a9c4a5943a33e5eb0e4bc4049579a03da56e3e68984ecca60b8fddd - Sigstore transparency entry: 909610912
- Sigstore integration time:
-
Permalink:
pipelabs/pd4castr@55cdc5e28a15e00c0e7617b78b8a7d9db337de01 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pipelabs
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main-deploy-prod.yml@55cdc5e28a15e00c0e7617b78b8a7d9db337de01 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file pd4castr_api_sdk-0.0.0-py3-none-any.whl.
File metadata
- Download URL: pd4castr_api_sdk-0.0.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2c16661e2c6b6c101444d56db99552fda1fee4f65382c8b39724609abf35cb6
|
|
| MD5 |
531645c00b77218c542220b21be5fda8
|
|
| BLAKE2b-256 |
1bd8a8fa8c34043ab20e7578a2544ad076d116fb8d352351edc85cbcb3035955
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pd4castr_api_sdk-0.0.0-py3-none-any.whl -
Subject digest:
a2c16661e2c6b6c101444d56db99552fda1fee4f65382c8b39724609abf35cb6 - Sigstore transparency entry: 909610913
- Sigstore integration time:
-
Permalink:
pipelabs/pd4castr@55cdc5e28a15e00c0e7617b78b8a7d9db337de01 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pipelabs
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main-deploy-prod.yml@55cdc5e28a15e00c0e7617b78b8a7d9db337de01 -
Trigger Event:
workflow_dispatch
-
Statement type: