You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

theforecastingcompany

Package Overview
Dependencies
Maintainers
0
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

theforecastingcompany

The official Python library for The Forecasting Company API

0.1.2
pipPyPI
Maintainers
0

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",
)

# 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.

Keywords

api

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts