Python Example — Forecasting Multiple SKUs
The following script shows how to loop through a list of SKU codes, call the Graphite Note Time Series Forecasting API for each, and save all daily predictions into a single CSV file. This example requests forecasts for October 2025 and assumes the model does not use regressors.
import requests
import pandas as pd
# --- CONFIGURATION ---
API_URL = "https://app.graphite-note.com/api/v1/prediction/model/[model-code]"
API_TOKEN = "Bearer YOUR_TOKEN_HERE"
# Example SKUs
sku_list = [f"SKU{i:03d}" for i in range(1, 11)]
# Prediction window
START_DATE = "2025-10-01"
END_DATE = "2025-10-31"
# --- STORAGE ---
all_results = []
# --- LOOP THROUGH SKUs ---
for sku in sku_list:
payload = {
"data": {
"predict_values": {
"startDate": START_DATE,
"endDate": END_DATE,
"sequenceID": sku
}
}
}
headers = {
"Authorization": API_TOKEN,
"Content-Type": "application/json"
}
response = requests.post(API_URL, json=payload, headers=headers)
response.raise_for_status()
data = response.json().get("data", [])
for row in data:
if "date" in row: # skip the trailing { "sequenceID": ... }
all_results.append({
"SKU": sku,
"Date": row["date"].split("T")[0],
"Predicted": row["predicted"],
"Predicted_Lower": row["predicted_lower"],
"Predicted_Upper": row["predicted_upper"]
})
# --- EXPORT TO CSV ---
df = pd.DataFrame(all_results)
df.to_csv("october_2025_forecasts.csv", index=False)
print("Saved results to october_2025_forecasts.csv")
This script:
Iterates through ten SKUs.
Sends a POST request for each SKU with the requested date range.
Collects all daily predictions, including lower and upper bounds.
Saves the results into a CSV file for further analysis.
Last updated
Was this helpful?