Reference

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.

ParameterTypeDefaultDescription
client_idstr(required)OAuth 2.0 client ID
client_secretstr(required)OAuth 2.0 client secret
timeoutfloat30.0HTTP 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.

ParameterTypeDefaultDescription
time_horizonstr or NoneNoneFilter models by time horizon
archivedboolFalseFilter 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) -> Model

Fetches a single model by its unique ID.

ParameterTypeDescription
model_idstrThe 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.

ParameterTypeDescription
model_idstrThe unique model ID

Returns: list[Sensitivity]

get_current_user

client.get_current_user() -> User

Returns 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
) -> ModelGroup

Fetches a single model group by its unique ID.

ParameterTypeDescription
model_group_idstrThe 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.

ParameterTypeDefaultDescription
model_group_idstrThe unique model group ID
archivedboolFalseFilter 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,
) -> ModelRunPage

Returns a paginated list of runs for a model, ordered by creation date descending.

ParameterTypeDefaultDescription
model_idstrThe unique model ID
limitint or NoneNoneMaximum number of runs to return
cursorstr or NoneNoneCursor from a previous page’s next_cursor for pagination
afterstr or NoneNoneISO 8601 datetime — return runs with run_datetime after this value
beforestr or NoneNoneISO 8601 datetime — return runs with run_datetime before this value
statusstr, list[str], or NoneNoneFilter by one or more run statuses
sensitivitystr or NoneNoneFilter 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
) -> ModelRun

Fetches a single model run by its unique ID.

ParameterTypeDescription
model_idstrThe unique model ID
run_idstrThe 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,
) -> ModelRunOutputResult

Fetches the output data for a completed model run. You can optionally include outputs from one or more comparison models for the same run datetime.

ParameterTypeDefaultDescription
model_idstrThe unique model ID
model_run_idstrThe unique run ID
comparison_modelstr, list[str], or NoneNoneOne or more model IDs to include for comparison

Returns: ModelRunOutputResult

get_latest_model

client.get_latest_model(
    model_group_id: str
) -> Model

A 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.

ParameterTypeDescription
model_group_idstrThe 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,
) -> ModelRun

A convenience method that returns the most recent completed run for a model. By default, it returns the latest base run, excluding sensitivity runs.

ParameterTypeDefaultDescription
model_idstrThe unique model ID
sensitivitystr or NoneNone"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,
) -> ModelRunOutputResult

A 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.

ParameterTypeDefaultDescription
model_idstrThe unique model ID
sensitivitystr or NoneNone"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) -> Model

Archives a model, setting archived=True, enabled=False, and public=False. This hides it by default in the pd4castr UI.

ParameterTypeDescription
model_idstrThe 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) -> Model

Unarchives a model, setting only archived=False. This makes it visible again in the pd4castr UI, but does not restore enabled or public.

ParameterTypeDescription
model_idstrThe 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() -> None

Closes 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.

FieldTypeDescription
idstrUnique model identifier
model_group_idstrID of the model group this model belongs to
namestrInternal model name
display_namestrHuman-readable display name
notesstrModel notes or description
revisionintModel revision number
docker_imagestrDocker image used to run the model
created_atstrISO 8601 creation timestamp
run_modeModelRunModeWhether the model runs automatically or on demand
horizonTimeHorizonThe model’s forecast time horizon
model_metadataModelMetadataAdditional metadata about the model
output_variableslist[OutputVariable]The model’s output variables with display config
output_specificationlist[ColumnSpecification]Deprecated. Always []. Use output_variables instead
inputslist[ModelInputSpecification] or NoneInput specifications, if any
archivedboolWhether the model is archived
tagslist[str]Tags associated with the model
sensitivitieslist[SensitivitySpecification]Sensitivity configurations
output_file_formatFileFormatOutput file format (json, csv, parquet)
display_timezonestrTimezone for displaying forecast results
forecast_variableForecastVariableSpecificationThe 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.

FieldTypeDescription
idstrUnique model group identifier
namestrModel group name
latest_revisionintThe highest revision number in the group
publicboolWhether the model group is publicly accessible
created_atstrISO 8601 creation timestamp

ModelRun

Represents a single execution of a model.

FieldTypeDescription
idstrUnique run identifier
statusModelRunStatusCurrent status of the run
created_atstrISO 8601 timestamp when the run was created
run_datetimestrISO 8601 forecast reference datetime
started_atstr or NoneISO 8601 timestamp when execution started
completed_atstr or NoneISO 8601 timestamp when execution completed
errored_atstr or NoneISO 8601 timestamp when the run failed
sensitivitySensitivity or NoneThe sensitivity used for this run, if any
errorstr or NoneError message if the run failed
container_idstr or NoneContainer ID for the run’s execution environment

ModelRunPage

A paginated response containing a list of model runs with cursor information.

FieldTypeDescription
datalist[ModelRun]The model runs for this page
next_cursorstr or NoneCursor to fetch the next page, if any
has_moreboolWhether more pages are available after this one

ModelRunOutputResult

Contains the output data for a model run, along with any comparison run outputs you requested.

FieldTypeDescription
runModelRunWithOutputThe primary run and its output data
comparison_runsdict[str, ModelRunWithOutput]Comparison outputs keyed by model ID

ModelRunWithOutput

A model run together with its forecast output data. This is used inside ModelRunOutputResult.

FieldTypeDescription
idstrUnique run identifier
run_datetimestrISO 8601 forecast reference datetime
sensitivitySensitivity or NoneThe sensitivity used for this run, if any
modelModelSummarySummary of the model that produced this run
coloursdict[str, str or None]Colour assignments for output series
datalist[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.

FieldTypeDescription
forecast_datetimestrISO 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.

FieldTypeDescription
idstrUnique model identifier
display_namestrHuman-readable display name
display_timezonestrTimezone for displaying forecast results

Sensitivity

Represents a named sensitivity for a model run.

FieldTypeDescription
idstrUnique sensitivity identifier
namestrHuman-readable sensitivity name
keystrStable key for identifying this sensitivity

SensitivitySpecification

Defines a sensitivity configuration on a model.

FieldTypeDescription
idstrUnique sensitivity identifier
namestrHuman-readable sensitivity name
keystrStable key for identifying this sensitivity

ModelInputSpecification

Describes an input that a model accepts.

FieldTypeDescription
idstrUnique input identifier
keystrMachine-readable input key

TimeHorizon

Describes the forecast time horizon for a model.

FieldTypeDescription
namestrFull name (for example, “Day Ahead”)
short_namestrAbbreviated name (for example, “DA”)
keystrMachine-readable key (for example, “day_ahead”)

ModelMetadata

Optional metadata associated with a model. All fields default to None.

FieldTypeDescription
descriptionstr or NoneExtended model description
release_datestr or NoneWhen the model was released
resolutionstr or NoneForecast resolution (for example, “30min”)

OutputVariable

Describes a single output variable for the model, including display configuration.

FieldTypeDescription
namestrOutput variable name
keystrStable key for identifying this variable
typestrData type of the output variable
series_keybool or NoneWhether this variable is a series key in charts
colourslist[str] or NoneHex colour codes for chart rendering

ColumnSpecification

Deprecated. Use OutputVariable instead.

Describes a single column in the model’s output data.

FieldTypeDescription
namestrColumn name
typestrData type of the column
uiUISpecification or NoneOptional display configuration

UISpecification

Controls how a column is displayed in the pd4castr UI.

FieldTypeDescription
series_keybool or NoneWhether the column is a series key
colourslist[str] or NoneHex colour codes for chart rendering

ForecastVariableSpecification

Describes the variable that a model forecasts.

FieldTypeDescription
namestrFull variable name (for example, “Price”)
short_namestrAbbreviated name (for example, “price”)
keystrMachine-readable key

User

Represents an authenticated user on the pd4castr platform.

FieldTypeDescription
idstrUnique user identifier
emailstrUser’s email address
organisationOrganisation or NoneThe user’s organisation

Organisation

Represents an organisation on the pd4castr platform.

FieldTypeDescription
idstrUnique organisation identifier
display_namestrOrganisation display name
slugstrURL-friendly organisation slug
domainslist[str]Email domains for the organisation
permissionslist[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.

ValueDescription
"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.

ValueDescription
"AUTOMATIC"Runs are triggered automatically
"ON_DEMAND"Runs are triggered manually

ModelRunStatus

Represents the lifecycle status of a model run.

ValueDescription
"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).

PropertyTypeDescription
status_codeintThe HTTP status code
messagestrA human-readable error message
bodyAny or NoneThe parsed response body, if available

NotFoundError

Raised when the API returns an HTTP 404 response.

Note: NotFoundError doesn’t inherit from ApiError. If you need to catch both, use separate except clauses.

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: