Skip to main content

Python client for TSFM time series forecasting with numpy support, confidence intervals, and multivariate predictions

Project description

TSFM Python Client

A Python client library for the TSFM (Time Series Foundation Model) Inference Platform. Supports both univariate and multivariate time series forecasting with confidence intervals.

Installation

pip install tsfm-client

Quick Start

import os
import numpy as np
from tsfm_client import TSFMClient

# Set your API key
os.environ['TSFM_API_KEY'] = 'your_api_key_here'

# Create client
client = TSFMClient(api_key=os.getenv('TSFM_API_KEY'))

# Make prediction with confidence intervals
data = np.array([10, 12, 13, 15, 17, 16, 18, 20, 22, 25])
response = client.predict(
    data=data,
    forecast_horizon=5,
    num_samples=100,
    confidence_intervals=[0.8, 0.95]
)

print(f"Forecast: {response.forecast}")
print(f"80% CI: {response.confidence_intervals['80%']}")
print(f"95% CI: {response.confidence_intervals['95%']}")

client.close()

Supported Models

  • chronos-t5-small: Fast univariate time series forecasting model
  • toto-open-base-1.0: Advanced multivariate time series forecasting model with confidence intervals

Supported Input Formats

The client accepts multiple data formats for maximum flexibility:

  • Numpy arrays: np.array([1, 2, 3]) (most efficient)
  • Python lists: [1, 2, 3] or [[1, 10], [2, 11]] (multivariate)
  • Pandas Series: pd.Series([1, 2, 3])
  • Pandas DataFrame: For multivariate data

Features

  • Native numpy support: No conversions needed, maximum efficiency
  • Multiple confidence intervals: Get 80%, 90%, 95% intervals in single request
  • Multivariate forecasting: Predict with multiple related time series
  • Flexible sampling: Control uncertainty estimation with num_samples
  • Error handling: Comprehensive exception handling for API errors
  • Context manager: Automatic resource cleanup

Advanced Usage

Multivariate Prediction

# 2D numpy array: time steps × variables
multivariate_data = np.array([[20, 65], [21, 63], [22, 61], [19, 67]])
response = client.predict(
    model_name='toto-open-base-1.0',
    data=multivariate_data,
    forecast_horizon=10,
    confidence_intervals=[0.8, 0.9, 0.95],
    num_samples=100
)

Context Manager

with TSFMClient() as client:
    response = client.predict(data=np.array([1, 2, 3, 4, 5]))
    print(response.forecast)

Error Handling

from tsfm_client import TSFMClient, AuthenticationError, APIError

try:
    client = TSFMClient()
    response = client.predict(data=np.array([1, 2, 3]))
except AuthenticationError:
    print("Invalid API key")
except APIError as e:
    print(f"API error: {e}")

Examples

For comprehensive examples including visualization and model comparison, see the demo notebook.

Requirements

  • Python >= 3.10
  • Valid TSFM API key
  • Dependencies: numpy, pandas, httpx, pydantic

API Reference

TSFMClient.predict()

predict(
    model_name: str = "chronos-t5-small",
    data: Union[np.ndarray, pd.Series, List[float], List[List[float]]],
    forecast_horizon: int = 12,
    confidence_intervals: Optional[List[float]] = None,
    num_samples: Optional[int] = None,
    time_interval_seconds: Optional[int] = None
) -> PredictionResponse

Parameters:

  • model_name: Model to use ('chronos-t5-small' or 'toto-open-base-1.0')
  • data: Time series data (1D for univariate, 2D for multivariate)
  • forecast_horizon: Number of steps to predict
  • confidence_intervals: List of confidence levels (e.g., [0.8, 0.95])
  • num_samples: Number of samples for uncertainty estimation
  • time_interval_seconds: Time between data points in seconds

Returns:

  • PredictionResponse with forecast, confidence intervals, and metadata

License

MIT License

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

tsfm_client-0.2.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

tsfm_client-0.2.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tsfm_client-0.2.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.13 Darwin/24.5.0

File hashes

Hashes for tsfm_client-0.2.0.tar.gz
Algorithm Hash digest
SHA256 717620e26c14bd780013d42c7894be069ce6551590632e62110bf3ac47577f43
MD5 c34c1a112304acc80d7b5198942c7e3c
BLAKE2b-256 f06099b8c6a0f7a50bcd78860e2d4c84ba7d0f00b667e5180726dd7ff289c9d8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tsfm_client-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.13 Darwin/24.5.0

File hashes

Hashes for tsfm_client-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ab34b70e0fdebd00f63b31c8e37b6a4b7a897c5dd6c5f4123a2df1a857e3db3
MD5 a8a32bbb6a29691c28740ee18677c963
BLAKE2b-256 07af17f41bd45bf50c038f0bc1d97f0a4a3d23e10b1d182b6e45ba6d09ac1aae

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