The Forecasting Company Python SDK

The python SDK provides a simple interface to make forecasts using the TFC API.
Documentation
The REST API documentation can be found on https://api.retrocast.com/docs.
To get an API key, visit the Authentication docs. In the API Keys section you will find an option to Sign in or, if you already signed in, a box containing your API key.
Installation
pip install theforecastingcompany
Usage
client = TFCClient()
timesfm_df = client.forecast(
train_df,
model=TFCModels.TimesFM_2
horizon=12,
freq="W",
)
tfc_global_df = client.forecast(
train_df,
model=TFCModels.TFCGlobal,
horizon=12,
freq="W",
static_variables=["unique_id","Group","Vendor","Category"],
add_holidays=True,
add_events=True,
country_isocode = "US"
)
If future_variables are available, make sure to pass also a future_df
when forecasting, and setting the future_variables
argument. All future variables must be present in the future_df
.
The cross_validate
function is basically the same, but takes a fcds
argument to define the FCDs to use for cross-validation. It also returns the target column in the output dataframe.
train_df
and future_df
should have id_col
(default "unique_id"), date_col
(default "ds"), and target_col
(default "target"). You can set the corresponding arguments if column names are different from default ones.
Versioning
This package generally follows SemVer conventions, though certain backwards-incompatible changes may be released as minor versions:
- Changes that only affect static types, without breaking runtime behavior.
- Changes to library internals which are technically public but not intended or documented for external use. (Please open a GitHub issue to let us know if you are relying on such internals.)
- Changes that we do not expect to impact the vast majority of users in practice.
We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
We are keen for your feedback; please open an issue with questions, bugs, or suggestions.
Determining the installed version
If you've upgraded to the latest version but aren't seeing any new features you were expecting then your python environment is likely still using an older version.
You can determine the version that is being used at runtime with:
import theforecastingcompany
print(theforecastingcompany.__version__)
Requirements
Python 3.11 or higher.