Skip to content

query_forecast

query_forecast(
    forecast_arn: Arn,
    filters: Filters,
    *,
    config_overrides: Optional[forecastqueryClientConfig] = None,
    start_date: Optional[DateTime] = None,
    end_date: Optional[DateTime] = None,
    next_token: Optional[NextToken] = None,
) -> QueryForecastResponse

Retrieves a forecast for a single item, filtered by the supplied criteria.

The criteria is a key-value pair. The key is either item_id (or the equivalent non-timestamp, non-target field) from the TARGET_TIME_SERIES dataset, or one of the forecast dimensions specified as part of the FeaturizationConfig object.

By default, QueryForecast returns the complete date range for the filtered forecast. You can request a specific date range.

To get the full forecast, use the CreateForecastExportJob operation.

The forecasts generated by Amazon Forecast are in the same timezone as the dataset that was used to create the predictor.

Parameters:

  • forecast_arn (Arn) –

    The Amazon Resource Name (ARN) of the forecast to query.

  • start_date (Optional[DateTime], default: None ) –

    The start date for the forecast. Specify the date using this format: yyyy-MM-dd'T'HH:mm:ss (ISO 8601 format). For example, 2015-01-01T08:00:00.

  • end_date (Optional[DateTime], default: None ) –

    The end date for the forecast. Specify the date using this format: yyyy-MM-dd'T'HH:mm:ss (ISO 8601 format). For example, 2015-01-01T20:00:00.

  • filters (Filters) –

    The filtering criteria to apply when retrieving the forecast. For example, to get the forecast for client_21 in the electricity usage dataset, specify the following:

    {"item_id" : "client_21"}

    To get the full forecast, use the CreateForecastExportJob operation.

  • next_token (Optional[NextToken], default: None ) –

    If the result of the previous request was truncated, the response includes a NextToken. To retrieve the next set of results, use the token in the next request. Tokens expire after 24 hours.

Raises:

Source code in docs_src/capo_forecastquery/_services/forecastquery.py
def query_forecast(
    self,
    forecast_arn: "capo_forecastquery.types.arn.Arn",
    filters: "capo_forecastquery.types.filters.Filters",
    *,
    config_overrides: Optional[forecastqueryClientConfig] = None,
    start_date: Optional["capo_forecastquery.types.date_time.DateTime"] = None,
    end_date: Optional["capo_forecastquery.types.date_time.DateTime"] = None,
    next_token: Optional["capo_forecastquery.types.next_token.NextToken"] = None,
) -> "capo_forecastquery.types.query_forecast_response.QueryForecastResponse":
    """<p>Retrieves a forecast for a single item, filtered by the supplied criteria.</p> <p>The criteria is a key-value pair. The key is either <code>item_id</code> (or the equivalent non-timestamp, non-target field) from the <code>TARGET_TIME_SERIES</code> dataset, or one of the forecast dimensions specified as part of the <code>FeaturizationConfig</code> object.</p> <p>By default, <code>QueryForecast</code> returns the complete date range for the filtered forecast. You can request a specific date range.</p> <p>To get the full forecast, use the <a href="https://docs.aws.amazon.com/en_us/forecast/latest/dg/API_CreateForecastExportJob.html">CreateForecastExportJob</a> operation.</p> <note> <p>The forecasts generated by Amazon Forecast are in the same timezone as the dataset that was used to create the predictor.</p> </note>

    Args:
        forecast_arn: <p>The Amazon Resource Name (ARN) of the forecast to query.</p>
        start_date: <p>The start date for the forecast. Specify the date using this format: yyyy-MM-dd'T'HH:mm:ss (ISO 8601 format). For example, 2015-01-01T08:00:00.</p>
        end_date: <p>The end date for the forecast. Specify the date using this format: yyyy-MM-dd'T'HH:mm:ss (ISO 8601 format). For example, 2015-01-01T20:00:00. </p>
        filters: <p>The filtering criteria to apply when retrieving the forecast. For example, to get the forecast for <code>client_21</code> in the electricity usage dataset, specify the following:</p> <p> <code>{"item_id" : "client_21"}</code> </p> <p>To get the full forecast, use the <a href="https://docs.aws.amazon.com/en_us/forecast/latest/dg/API_CreateForecastExportJob.html">CreateForecastExportJob</a> operation.</p>
        next_token: <p>If the result of the previous request was truncated, the response includes a <code>NextToken</code>. To retrieve the next set of results, use the token in the next request. Tokens expire after 24 hours.</p>

    Raises:
        capo_forecastquery.errors.invalid_input_exception.InvalidInputException: <p>The value is invalid or is too long.</p>
        capo_forecastquery.errors.invalid_next_token_exception.InvalidNextTokenException: <p>The token is not valid. Tokens expire after 24 hours.</p>
        capo_forecastquery.errors.limit_exceeded_exception.LimitExceededException: <p>The limit on the number of requests per second has been exceeded.</p>
        capo_forecastquery.errors.resource_in_use_exception.ResourceInUseException: <p>The specified resource is in use.</p>
        capo_forecastquery.errors.resource_not_found_exception.ResourceNotFoundException: <p>We can't find that resource. Check the information that you've provided and try again.</p>
        capo_forecastquery.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_forecastquery.types.query_forecast_request.QueryForecastRequest]",
    ) -> OperationResponse[
        "capo_forecastquery.types.query_forecast_response.QueryForecastResponse"
    ]:
        import capo_forecastquery._operations.amazon_forecast_runtime.query_forecast

        output, http_response = (
            capo_forecastquery._operations.amazon_forecast_runtime.query_forecast.query_forecast(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("QueryForecast")
    )
    input_: capo_forecastquery.types.query_forecast_request.QueryForecastRequest = {
        "forecast_arn": forecast_arn,
        "filters": filters,
    }
    if start_date is not None:
        input_["start_date"] = start_date
    if end_date is not None:
        input_["end_date"] = end_date
    if next_token is not None:
        input_["next_token"] = next_token

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output