The official Python library for The Forecasting Company API
Project description
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
# install from PyPI
pip install theforecastingcompany
Usage
# By default it will look for api_key in os.getenv("TFC_API_KEY"). Otherwise you can explicity set the api_key argument
client = TFCClient()
# Compute forecast for a single model
timesfm_df = client.forecast(
train_df,
model=TFCModels.TimesFM_2 # StrEnum defined in utils. You can also pass the model name as a string, eg timesfm-2
horizon=12,
freq="W",
)
# Global Model with static variables
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file theforecastingcompany-0.1.3.tar.gz.
File metadata
- Download URL: theforecastingcompany-0.1.3.tar.gz
- Upload date:
- Size: 39.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5a7b84fb9a7adb9562f8333a95d1ae953e188224964b9da44d7cb4f69819245
|
|
| MD5 |
6894be80dd235d4d6970664ba0b625a2
|
|
| BLAKE2b-256 |
a472acb065ed2c2319637bbfc32349bdb8d1c1b3e3acd6ebdd6ac2136adf17e0
|
File details
Details for the file theforecastingcompany-0.1.3-py3-none-any.whl.
File metadata
- Download URL: theforecastingcompany-0.1.3-py3-none-any.whl
- Upload date:
- Size: 20.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c834bd209ec3b5ac30578f1377c99499892e2e690ed0ccd6c4ffacbb3e402ec3
|
|
| MD5 |
71eb625c555b3aac4b6af8a699e2487c
|
|
| BLAKE2b-256 |
4bbdbe7b1a47440fbdbaf09489ac11be549b94d05ed40bde5f26679aa8e0a2f0
|