calibsunapi package

Subpackages

Submodules

calibsunapi.client module

Main module for the Calibsun API client.

class calibsunapi.client.CalibsunApiClient(calibsun_client_id: str | None = None, calibsun_client_secret: str | None = None)

Bases: object

Main class for the Calibsun API client.

get_deterministic_forecast(forecast_time: time, site_id: str, target: str, run_tag: str | None = None) dict

Retrieves a deterministic forecast for a specific site and target at a given forecast time for the current day.

Parameters:
  • forecast_time (time) – The time for which the forecast is requested.

  • site_id (str) – The identifier of the site for which the forecast is requested.

  • target (str) – The target parameter for the forecast.

  • run_tag (Optional[str], optional) – An optional run tag to filter the forecast. Defaults to None.

Returns:

The JSON response from the API containing the deterministic forecast data.

Return type:

dict

Raises:
  • HTTPError – If the HTTP request returned an unsuccessful status code.

  • NotAuthenticatedError – If the client is not authenticated.

get_forecast(forecast_time: time, site_id: str, target: str, run_tag: str | None = None) dict

Retrieve the forecast for a specific time at the current day, site, and target.

Parameters:
  • forecast_time (time) – The time for which the forecast is requested.

  • site_id (str) – The identifier of the site for which the forecast is requested.

  • target (str) – The target parameter for the forecast.

  • run_tag (Optional[str], optional) – An optional run tag to filter the forecast. Defaults to None.

Returns:

The forecast data in JSON format.

Return type:

dict

Raises:
  • HTTPError – If the HTTP request returned an unsuccessful status code.

  • NotAuthenticatedError – If the client is not authenticated.

get_forecast_availability(site_id: str, target: str, start_date: datetime = datetime.datetime(2026, 1, 22, 12, 14, 55, 762489, tzinfo=datetime.timezone.utc), end_date: datetime = datetime.datetime(2026, 1, 23, 12, 14, 55, 762492, tzinfo=datetime.timezone.utc), run_tag: str | None = None) list[datetime]
get_historical_deterministic_forecast(forecast_datetime: datetime, site_id: str, target: str, run_tag: str | None = None) dict

Retrieve the historical forecast for a specific datetime, site, and target.

Parameters:
  • forecast_datetime (datetime) – The datetime for which the forecast is requested.

  • site_id (str) – The identifier of the site for which the forecast is requested.

  • target (str) – The target parameter for the forecast.

  • run_tag (Optional[str], optional) – An optional run tag to filter the forecast. Defaults to None.

Returns:

The historical forecast data in JSON format.

Return type:

dict

Raises:
  • HTTPError – If the HTTP request returned an unsuccessful status code.

  • NotAuthenticatedError – If the client is not authenticated.

get_historical_forecast(forecast_datetime: datetime, site_id: str, target: str, run_tag: str | None = None) dict

Retrieve the historical forecast for a specific datetime, site, and target.

Parameters:
  • forecast_datetime (datetime) – The datetime for which the forecast is requested.

  • site_id (str) – The identifier of the site for which the forecast is requested.

  • target (str) – The target parameter for the forecast.

  • run_tag (Optional[str], optional) – An optional run tag to filter the forecast. Defaults to None.

Returns:

The historical forecast data in JSON format.

Return type:

dict

Raises:
  • HTTPError – If the HTTP request returned an unsuccessful status code.

  • NotAuthenticatedError – If the client is not authenticated.

get_historical_probabilistic_forecast(forecast_datetime: datetime, site_id: str, target: str, run_tag: str | None = None) dict

Retrieve the historical probabilistic forecast for a specific datetime, site, and target.

Parameters:
  • forecast_datetime (datetime) – The datetime for which the forecast is requested.

  • site_id (str) – The identifier of the site for which the forecast is requested.

  • target (str) – The target parameter for the forecast.

  • run_tag (Optional[str], optional) – An optional run tag to filter the forecast. Defaults to None.

Returns:

The historical probabilistic forecast data in JSON format.

Return type:

dict

Raises:
  • HTTPError – If the HTTP request returned an unsuccessful status code.

  • NotAuthenticatedError – If the client is not authenticated.

get_latest_forecast(site_id: str, target: str, run_tag: str | None = None) dict

Retrieve the latest forecast for a given site and target. :param site_id: The identifier of the site for which the forecast is requested. :type site_id: str :param target: The target parameter for the forecast. :type target: str :param run_tag: An optional run tag to filter the forecast. Defaults to None. :type run_tag: Optional[str], optional

Returns:

A dictionary containing the latest forecast data.

Return type:

dict

Raises:
  • HTTPError – If the HTTP request returned an unsuccessful status code.

  • NotAuthenticatedError – If the client is not authenticated.

get_latest_forecast_deterministic(site_id: str, target: str, run_tag: str | None = None) dict

Fetches the latest deterministic forecast for a given site and target. :param site_id: The identifier of the site for which the forecast is requested. :type site_id: str :param target: The target parameter for the forecast. :type target: str :param run_tag: An optional run tag to filter the forecast. Defaults to None. :type run_tag: Optional[str], optional

Returns:

A dictionary containing the latest deterministic forecast data.

Return type:

dict

Raises:
  • HTTPError – If the HTTP request returned an unsuccessful status code.

  • NotAuthenticatedError – If the client is not authenticated.

get_latest_forecast_probabilistic(site_id: str, target: str, run_tag: str | None = None) dict

Retrieve the latest probabilistic forecast for a given site and target. :param site_id: The identifier of the site for which to retrieve the forecast. :type site_id: str :param target: The target parameter for the forecast. :type target: str :param run_tag: An optional run tag to filter the forecast. Defaults to None. :type run_tag: Optional[str], optional

Returns:

A dictionary containing the latest probabilistic forecast data.

Return type:

dict

Raises:
  • HTTPError – If the HTTP request returned an unsuccessful status code.

  • NotAuthenticatedError – If the client is not authenticated.

get_probabilistic_forecast(forecast_time: time, site_id: str, target: str, run_tag: str | None = None) dict

Retrieve a probabilistic forecast for a specific site and target at a given forecast time for the current day. :param forecast_time: The time for which the forecast is requested. :type forecast_time: time :param site_id: The identifier of the site for which the forecast is requested. :type site_id: str :param target: The target variable for the forecast (e.g., temperature, wind speed). :type target: str :param run_tag: An optional run tag to filter the forecast. Defaults to None. :type run_tag: Optional[str], optional

Returns:

A dictionary containing the probabilistic forecast data.

Return type:

dict

Raises:
  • HTTPError – If the HTTP request returned an unsuccessful status code.

  • NotAuthenticatedError – If the client is not authenticated.

list_plants() list[Plant]

Retrieve a list of plants from the API.

This method sends a GET request to the LISTPLANT endpoint and returns a list of Plant objects.

Returns:

A list of Plant objects retrieved from the API.

Return type:

list[Plant]

Raises:

HTTPError – If the HTTP request returned an unsuccessful status code.

push_measurements(site_id: str, format: UploadMeasurementsFormats = 'json', filepath: str | None = None, data: Any | None = None) Response

Push measurements to the specified site. :param site_id: The ID of the site to which the measurements will be uploaded. :type site_id: str :param format: The format of the upload. Defaults to UploadMeasurementsFormats.JSON. :type format: UploadMeasurementsFormats, optional :param filepath: The path to the file containing the measurements. Defaults to None. :type filepath: Optional[str], optional :param data: The data to be uploaded if no file is provided. Defaults to None. :type data: Optional[Any], optional

Returns:

The response from the server after attempting to upload the measurements.

Return type:

requests.Response

Raises:
  • HTTPError – If the upload fails and the server returns an HTTP error.

  • NotAuthenticatedError – If the client is not authenticated.

  • ValueError – If both filepath and data are provided or if neither is provided

property token: Token

calibsunapi.decorators module

calibsunapi.decorators.requires_authentication(func)

calibsunapi.endpoints module

class calibsunapi.endpoints.EndpointRoutes

Bases: object

FIXEDTIMEFORECAST = 'https://api.calibsun.com/api/v2/public/fixedtimeforecast/{time}/{site_id}/{target}'
FIXEDTIMEFORECAST_DET = 'https://api.calibsun.com/api/v2/public/fixedtimeforecast/deterministic/{time}/{site_id}/{target}'
FIXEDTIMEFORECAST_PROBA = 'https://api.calibsun.com/api/v2/public/fixedtimeforecast/probabilistic/{time}/{site_id}/{target}'
FORECASTAVAILABILITY = 'https://api.calibsun.com/api/v2/public/forecastavailability/{site_id}/{target}'
HISTORICAL_FORECAST = 'https://api.calibsun.com/api/v2/public/forecast/{datetime}/{siteid}/{target}'
HISTORICAL_FORECAST_DET = 'https://api.calibsun.com/api/v2/public/forecast/{datetime}/deterministic/{siteid}/{target}'
HISTORICAL_FORECAST_PROBA = 'https://api.calibsun.com/api/v2/public/forecast/{datetime}/probabilistic/{siteid}/{target}'
LATESTFORECAST = 'https://api.calibsun.com/api/v2/public/latestforecast/{site_id}/{target}'
LATESTFORECAST_DET = 'https://api.calibsun.com/api/v2/public/latestforecast/deterministic{site_id}/{target}'
LATESTFORECAST_PROBA = 'https://api.calibsun.com/api/v2/public/latestforecast/probabilistic/{site_id}/{target}'
LISTPLANT = 'https://api.calibsun.com/api/v2/public/listplant'
TOKEN = 'https://api.calibsun.com/api/v2/open/token'
UPLOAD = 'https://api.calibsun.com/api/v2/public/uploadmeasurements/{site_id}/{format}'

calibsunapi.exceptions module

exception calibsunapi.exceptions.DocDefaultException(msg=None, *args, **kwargs)

Bases: Exception

Subclass exceptions use docstring as default message

exception calibsunapi.exceptions.NoCredentialsError(msg=None, *args, **kwargs)

Bases: DocDefaultException

Please provide CALIBSUN_CLIENT_ID and CALIBSUN_CLIENT_SECRET in environment variables or pass values when initializing client.

exception calibsunapi.exceptions.NotAuthenticatedError(msg=None, *args, **kwargs)

Bases: DocDefaultException

Not authenticated with Calibsun API. Please provide CALIBSUN_CLIENT_ID and CALIBSUN_CLIENT_SECRET in environment variables or pass values when initializing client.

calibsunapi.token module

class calibsunapi.token.Token(access_token: str, token_type: str, expires_in: int, created_at: float = 1769170495.7617064)

Bases: object

access_token: str
created_at: float = 1769170495.7617064
expires_in: int
is_expired()
token_type: str

calibsunapi.utils module

calibsunapi.utils.format_time(ftime: time) str

Converts a time object to calibsun api’s format.

Parameters:

time – The time object to be formatted.

Returns:

The formatted time string.

Module contents