get_modelsget_modelget_model_sensitivitiesget_current_userget_model_groupsget_model_groupget_model_group_modelsget_model_runsget_model_runget_model_run_outputget_latest_modelget_latest_model_runget_latest_model_run_outputarchive_modelunarchive_modelcloseData ModelsModelModelGroupModelRunModelRunPageModelRunOutputResultModelRunWithOutputModelRunOutputDataModelSummarySensitivitySensitivitySpecificationModelInputSpecificationTimeHorizonModelMetadataOutputVariableColumnSpecificationUISpecificationForecastVariableSpecificationUserOrganisationEnumsFileFormatModelRunModeModelRunStatusExceptionsApiErrorNotFoundErrorError Handling ExampleNext StepsReference
This is the complete API reference for the pd4castr-api-sdk Python package. It
documents every public class, method, data model, and exception.
Client
The Client class is the main entry point for interacting with the pd4castr
API.
Constructor
from pd4castr_api_sdk import Client
client = Client(
*,
client_id: str,
client_secret: str,
timeout: float = 30.0,
)All parameters are keyword-only.
| Parameter | Type | Default | Description |
|---|---|---|---|
client_id | str | (required) | OAuth 2.0 client ID |
client_secret | str | (required) | OAuth 2.0 client secret |
timeout | float | 30.0 | HTTP request timeout in seconds |
The client supports the context manager protocol, so you can use it with a
with statement to automatically close the connection:
with Client(client_id="...", client_secret="...") as client:
models = client.get_models()Methods
These are all the public methods available on the Client class.
get_models
client.get_models(
*,
time_horizon: str | None = None,
archived: bool = False,
) -> list[Model]Returns a list of all models accessible to the authenticated user, including your organisation’s private models and any public models.
| Parameter | Type | Default | Description |
|---|---|---|---|
time_horizon | str or None | None | Filter models by time horizon |
archived | bool | False | Filter by archived status. Defaults to False (excludes archived models) |
Valid time_horizon values:
"day_ahead""week_ahead""quarterly""historical"
When time_horizon is None, all models are returned regardless of their time
horizon.
Returns: list[Model]
get_model
client.get_model(model_id: str) -> ModelFetches a single model by its unique ID.
| Parameter | Type | Description |
|---|---|---|
model_id | str | The unique model ID |
Returns: Model
Raises: NotFoundError if no model exists with the given ID.
get_model_sensitivities
client.get_model_sensitivities(
model_id: str
) -> list[Sensitivity]Returns the list of sensitivities available for a model.
| Parameter | Type | Description |
|---|---|---|
model_id | str | The unique model ID |
Returns: list[Sensitivity]
get_current_user
client.get_current_user() -> UserReturns the profile and organisation details for the authenticated user.
Returns: User
get_model_groups
client.get_model_groups() -> list[ModelGroup]Returns all model groups accessible to the authenticated user. A model group contains one or more model revisions.
Returns: list[ModelGroup]
get_model_group
client.get_model_group(
model_group_id: str
) -> ModelGroupFetches a single model group by its unique ID.
| Parameter | Type | Description |
|---|---|---|
model_group_id | str | The unique model group ID |
Returns: ModelGroup
Raises: NotFoundError if no model group exists with the given ID.
get_model_group_models
client.get_model_group_models(
model_group_id: str,
*,
archived: bool = False,
) -> list[Model]Returns all model revisions that belong to a model group.
| Parameter | Type | Default | Description |
|---|---|---|---|
model_group_id | str | The unique model group ID | |
archived | bool | False | Filter by archived status. Defaults to False (excludes archived models) |
Returns: list[Model]
get_model_runs
client.get_model_runs(
model_id: str,
*,
limit: int | None = None,
cursor: str | None = None,
after: str | None = None,
before: str | None = None,
status: str | list[str] | None = None,
sensitivity: str | None = None,
) -> ModelRunPageReturns a paginated list of runs for a model, ordered by creation date descending.
| Parameter | Type | Default | Description |
|---|---|---|---|
model_id | str | The unique model ID | |
limit | int or None | None | Maximum number of runs to return |
cursor | str or None | None | Cursor from a previous page’s next_cursor for pagination |
after | str or None | None | ISO 8601 datetime — return runs with run_datetime after this value |
before | str or None | None | ISO 8601 datetime — return runs with run_datetime before this value |
status | str, list[str], or None | None | Filter by one or more run statuses |
sensitivity | str or None | None | Filter by sensitivity: "base" for base runs only, or a sensitivity ID to match |
When sensitivity is None (the default), all runs are returned including both
base and sensitivity runs.
Returns: ModelRunPage
get_model_run
client.get_model_run(
model_id: str, run_id: str
) -> ModelRunFetches a single model run by its unique ID.
| Parameter | Type | Description |
|---|---|---|
model_id | str | The unique model ID |
run_id | str | The unique run ID |
Returns: ModelRun
Raises: NotFoundError if no model run exists with the given ID.
get_model_run_output
client.get_model_run_output(
model_id: str,
model_run_id: str,
*,
comparison_model: str | list[str] | None = None,
) -> ModelRunOutputResultFetches the output data for a completed model run. You can optionally include outputs from one or more comparison models for the same run datetime.
| Parameter | Type | Default | Description |
|---|---|---|---|
model_id | str | The unique model ID | |
model_run_id | str | The unique run ID | |
comparison_model | str, list[str], or None | None | One or more model IDs to include for comparison |
Returns: ModelRunOutputResult
get_latest_model
client.get_latest_model(
model_group_id: str
) -> ModelA convenience method that returns the latest model revision in a model group. It fetches the models in the group and returns the one with the highest revision number.
| Parameter | Type | Description |
|---|---|---|
model_group_id | str | The unique model group ID |
Returns: Model
Raises: NotFoundError if the model group contains no models.
get_latest_model_run
client.get_latest_model_run(
model_id: str,
*,
sensitivity: str | None = None,
) -> ModelRunA convenience method that returns the most recent completed run for a model. By default, it returns the latest base run, excluding sensitivity runs.
| Parameter | Type | Default | Description |
|---|---|---|---|
model_id | str | The unique model ID | |
sensitivity | str or None | None | "base" for base runs only (same as default), or a sensitivity ID to filter by that instead |
When sensitivity is None (the default), only base runs are considered.
Returns: ModelRun
Raises: NotFoundError if the model has no matching completed runs.
get_latest_model_run_output
client.get_latest_model_run_output(
model_id: str,
*,
sensitivity: str | None = None,
) -> ModelRunOutputResultA convenience method that fetches the output data for the most recent completed
run of a model. This combines get_latest_model_run and get_model_run_output
into a single call. By default, it returns the output from the latest base
run.
| Parameter | Type | Default | Description |
|---|---|---|---|
model_id | str | The unique model ID | |
sensitivity | str or None | None | "base" for base runs only (same as default), or a sensitivity ID to get that sensitivity’s latest run |
Returns: ModelRunOutputResult
archive_model
client.archive_model(model_id: str) -> ModelArchives a model, setting archived=True, enabled=False, and public=False.
This hides it by default in the pd4castr UI.
| Parameter | Type | Description |
|---|---|---|
model_id | str | The unique model ID |
Returns: Model — The updated model.
Raises: NotFoundError if the model is not found or not owned by your
organisation.
unarchive_model
client.unarchive_model(model_id: str) -> ModelUnarchives a model, setting only archived=False. This makes it visible again
in the pd4castr UI, but does not restore enabled or public.
| Parameter | Type | Description |
|---|---|---|
model_id | str | The unique model ID |
Returns: Model — The updated model.
Raises: NotFoundError if the model is not found or not owned by your
organisation.
close
client.close() -> NoneCloses the underlying HTTP connection. After calling close(), the client can’t
make further requests. If you use the client as a context manager, this is
called automatically.
Data Models
All data models use Pydantic and are returned as typed Python objects. Unknown fields from the API are ignored automatically.
Model
Represents a forecast model on the pd4castr platform.
| Field | Type | Description |
|---|---|---|
id | str | Unique model identifier |
model_group_id | str | ID of the model group this model belongs to |
name | str | Internal model name |
display_name | str | Human-readable display name |
notes | str | Model notes or description |
revision | int | Model revision number |
docker_image | str | Docker image used to run the model |
created_at | str | ISO 8601 creation timestamp |
run_mode | ModelRunMode | Whether the model runs automatically or on demand |
horizon | TimeHorizon | The model’s forecast time horizon |
model_metadata | ModelMetadata | Additional metadata about the model |
output_variables | list[OutputVariable] | The model’s output variables with display config |
output_specification | list[ColumnSpecification] | Deprecated. Always []. Use output_variables instead |
inputs | list[ModelInputSpecification] or None | Input specifications, if any |
archived | bool | Whether the model is archived |
tags | list[str] | Tags associated with the model |
sensitivities | list[SensitivitySpecification] | Sensitivity configurations |
output_file_format | FileFormat | Output file format (json, csv, parquet) |
display_timezone | str | Timezone for displaying forecast results |
forecast_variable | ForecastVariableSpecification | The variable being forecast |
ModelGroup
Represents a group of model revisions. Each time you publish a new revision of a model, it’s added to the same model group.
| Field | Type | Description |
|---|---|---|
id | str | Unique model group identifier |
name | str | Model group name |
latest_revision | int | The highest revision number in the group |
public | bool | Whether the model group is publicly accessible |
created_at | str | ISO 8601 creation timestamp |
ModelRun
Represents a single execution of a model.
| Field | Type | Description |
|---|---|---|
id | str | Unique run identifier |
status | ModelRunStatus | Current status of the run |
created_at | str | ISO 8601 timestamp when the run was created |
run_datetime | str | ISO 8601 forecast reference datetime |
started_at | str or None | ISO 8601 timestamp when execution started |
completed_at | str or None | ISO 8601 timestamp when execution completed |
errored_at | str or None | ISO 8601 timestamp when the run failed |
sensitivity | Sensitivity or None | The sensitivity used for this run, if any |
error | str or None | Error message if the run failed |
container_id | str or None | Container ID for the run’s execution environment |
ModelRunPage
A paginated response containing a list of model runs with cursor information.
| Field | Type | Description |
|---|---|---|
data | list[ModelRun] | The model runs for this page |
next_cursor | str or None | Cursor to fetch the next page, if any |
has_more | bool | Whether more pages are available after this one |
ModelRunOutputResult
Contains the output data for a model run, along with any comparison run outputs you requested.
| Field | Type | Description |
|---|---|---|
run | ModelRunWithOutput | The primary run and its output data |
comparison_runs | dict[str, ModelRunWithOutput] | Comparison outputs keyed by model ID |
ModelRunWithOutput
A model run together with its forecast output data. This is used inside
ModelRunOutputResult.
| Field | Type | Description |
|---|---|---|
id | str | Unique run identifier |
run_datetime | str | ISO 8601 forecast reference datetime |
sensitivity | Sensitivity or None | The sensitivity used for this run, if any |
model | ModelSummary | Summary of the model that produced this run |
colours | dict[str, str or None] | Colour assignments for output series |
data | list[ModelRunOutputData] | The forecast output rows |
ModelRunOutputData
A single row of forecast output data. Every row has a forecast_datetime field,
plus additional fields that depend on the model’s output specification.
| Field | Type | Description |
|---|---|---|
forecast_datetime | str | ISO 8601 forecast target datetime |
| (dynamic fields) | Additional fields defined by the model’s output specification |
This model uses Pydantic’s extra="allow" configuration, so any fields beyond
forecast_datetime are accessible as attributes or via dictionary-style access.
ModelSummary
A compact representation of a model, used inside output results.
| Field | Type | Description |
|---|---|---|
id | str | Unique model identifier |
display_name | str | Human-readable display name |
display_timezone | str | Timezone for displaying forecast results |
Sensitivity
Represents a named sensitivity for a model run.
| Field | Type | Description |
|---|---|---|
id | str | Unique sensitivity identifier |
name | str | Human-readable sensitivity name |
key | str | Stable key for identifying this sensitivity |
SensitivitySpecification
Defines a sensitivity configuration on a model.
| Field | Type | Description |
|---|---|---|
id | str | Unique sensitivity identifier |
name | str | Human-readable sensitivity name |
key | str | Stable key for identifying this sensitivity |
ModelInputSpecification
Describes an input that a model accepts.
| Field | Type | Description |
|---|---|---|
id | str | Unique input identifier |
key | str | Machine-readable input key |
TimeHorizon
Describes the forecast time horizon for a model.
| Field | Type | Description |
|---|---|---|
name | str | Full name (for example, “Day Ahead”) |
short_name | str | Abbreviated name (for example, “DA”) |
key | str | Machine-readable key (for example, “day_ahead”) |
ModelMetadata
Optional metadata associated with a model. All fields default to None.
| Field | Type | Description |
|---|---|---|
description | str or None | Extended model description |
release_date | str or None | When the model was released |
resolution | str or None | Forecast resolution (for example, “30min”) |
OutputVariable
Describes a single output variable for the model, including display configuration.
| Field | Type | Description |
|---|---|---|
name | str | Output variable name |
key | str | Stable key for identifying this variable |
type | str | Data type of the output variable |
series_key | bool or None | Whether this variable is a series key in charts |
colours | list[str] or None | Hex colour codes for chart rendering |
ColumnSpecification
Deprecated. Use
OutputVariableinstead.
Describes a single column in the model’s output data.
| Field | Type | Description |
|---|---|---|
name | str | Column name |
type | str | Data type of the column |
ui | UISpecification or None | Optional display configuration |
UISpecification
Controls how a column is displayed in the pd4castr UI.
| Field | Type | Description |
|---|---|---|
series_key | bool or None | Whether the column is a series key |
colours | list[str] or None | Hex colour codes for chart rendering |
ForecastVariableSpecification
Describes the variable that a model forecasts.
| Field | Type | Description |
|---|---|---|
name | str | Full variable name (for example, “Price”) |
short_name | str | Abbreviated name (for example, “price”) |
key | str | Machine-readable key |
User
Represents an authenticated user on the pd4castr platform.
| Field | Type | Description |
|---|---|---|
id | str | Unique user identifier |
email | str | User’s email address |
organisation | Organisation or None | The user’s organisation |
Organisation
Represents an organisation on the pd4castr platform.
| Field | Type | Description |
|---|---|---|
id | str | Unique organisation identifier |
display_name | str | Organisation display name |
slug | str | URL-friendly organisation slug |
domains | list[str] | Email domains for the organisation |
permissions | list[str] | Granted permission strings |
Enums
The SDK defines several string enumerations. Because they extend Python’s
StrEnum, you can compare them directly with plain strings.
FileFormat
Supported output file formats for model data.
| Value | Description |
|---|---|
"json" | JSON format |
"csv" | Comma-separated values |
"parquet" | Apache Parquet format |
if model.output_file_format == "parquet":
print("This model outputs Parquet files")ModelRunMode
Defines how a model’s runs are triggered.
| Value | Description |
|---|---|
"AUTOMATIC" | Runs are triggered automatically |
"ON_DEMAND" | Runs are triggered manually |
ModelRunStatus
Represents the lifecycle status of a model run.
| Value | Description |
|---|---|
"pending" | Run is queued and waiting to start |
"input_files_prepared" | Input files have been prepared |
"running" | Run is currently executing |
"completed" | Run finished successfully |
"failed" | Run encountered an error |
Exceptions
The SDK defines two exception types for error handling.
ApiError
Raised when the API returns an HTTP 4xx or 5xx response (except 404, which
raises NotFoundError instead).
| Property | Type | Description |
|---|---|---|
status_code | int | The HTTP status code |
message | str | A human-readable error message |
body | Any or None | The parsed response body, if available |
NotFoundError
Raised when the API returns an HTTP 404 response.
Note:
NotFoundErrordoesn’t inherit fromApiError. If you need to catch both, use separateexceptclauses.
Error Handling Example
This example shows how to handle both exception types.
from pd4castr_api_sdk import Client, ApiError, NotFoundError
with Client(client_id="...", client_secret="...") as client:
try:
model = client.get_model("non-existent-id")
except NotFoundError:
print("Model not found")
except ApiError as e:
print(f"API error {e.status_code}: {e.message}")Next Steps
Now that you’re familiar with the SDK’s API surface, explore these guides to see it in action:
- Discover models — browse and filter available models
- Fetch the latest forecast — retrieve the most recent output for a model
- Browse historical runs — paginate through past model runs
- Compare models — fetch comparison outputs across models