Skip to main content

The official Python library for The Forecasting Company API

Project description

The Forecasting Company Python SDK

PyPI version API status

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",
    quantiles=[0.5,0.1,0.9]
)

# 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",
        # Fit a separate global model for each group.
        # If None, a single global model is fitted to all timeseries.
        partition_by=["Group"]
    )

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:

  1. Changes that only affect static types, without breaking runtime behavior.
  2. 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.)
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

theforecastingcompany-0.2.0.tar.gz (41.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

theforecastingcompany-0.2.0-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file theforecastingcompany-0.2.0.tar.gz.

File metadata

File hashes

Hashes for theforecastingcompany-0.2.0.tar.gz
Algorithm Hash digest
SHA256 dfca4aca2c1477d56e85dce3d7ade736f023ac8695ed1f1c1c35064560a0599e
MD5 72c3d00ee5c6b2e007286c8b6b3ac7dd
BLAKE2b-256 67210976d009412c28dc80819865e154045318d50cc04577f0c7ef9ec0628d3a

See more details on using hashes here.

File details

Details for the file theforecastingcompany-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for theforecastingcompany-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b5f44b629c86f46b8e48340fab62a775d27d934e3450cba0db8a96a83b2e482b
MD5 8c0c4ddf3868e94bfe80652d4ed8eeb3
BLAKE2b-256 951618de2569b14b615d22359ca2443922fa24eb34dbf21975071bfb44a83b7c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page