Skip to main content

Python client library for TSFM Inference Platform

Project description

TSFM Python Client

A simple Python client for the TSFM (Time Series Foundation Model) Inference Platform.

Installation

git clone git@github.com:S-FM/tsfm-python-client.git
cd tsfm-python-client
poetry install

Quick Start

1. Set up your API key

export TSFM_API_KEY="your_api_key_here"

2. Make predictions

from tsfm_client import predict

# Simple prediction
data = [10, 12, 13, 15, 17, 16, 18, 20, 22, 25]
response = predict(data=data, forecast_horizon=5)
print(f"Forecast: {response.forecast}")

Supported Models

  • chronos-t5-small: Fast CPU inference for time series forecasting

API Reference

predict() function

predict(
    data: Union[List[float], pd.Series, TimeSeriesData],
    model: str = "chronos-t5-small",
    forecast_horizon: int = 12,
    confidence_intervals: bool = False,
    base_url: str = "http://localhost:8000"
) -> PredictionResponse

TSFMClient class

from tsfm_client import TSFMClient

client = TSFMClient()  # Uses TSFM_API_KEY environment variable

# Make predictions
response = client.predict(data=[1, 2, 3, 4, 5], forecast_horizon=3)

# List models
models = client.list_models()

# Get model info
info = client.get_model_info("chronos-t5-small")

# Health check
health = client.health_check()

client.close()

Examples

With Pandas

import pandas as pd
from tsfm_client import predict

# Create time series data
dates = pd.date_range('2024-01-01', periods=30, freq='D')
ts_data = pd.Series([100, 102, 98, 105, 107, ...], index=dates)

# Make prediction
response = predict(
    data=ts_data,
    forecast_horizon=7,
    confidence_intervals=True
)

Using Context Manager

from tsfm_client import TSFMClient

with TSFMClient() as client:
    response = client.predict(data=[1, 2, 3, 4, 5])
    print(f"Forecast: {response.forecast}")

Error Handling

from tsfm_client import TSFMClient, AuthenticationError, APIError

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

Response Format

class PredictionResponse:
    model_name: str
    forecast: List[float]
    confidence_intervals: Optional[Dict]
    metadata: Dict[str, Any]

Requirements

  • Python >= 3.11
  • Valid TSFM API key
  • Running TSFM server

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.1.0.tar.gz (5.4 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.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tsfm_client-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 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.1.0.tar.gz
Algorithm Hash digest
SHA256 78910b531bbddef07f6c6d81fc9ae2b5b41f5a3108f6f384f12b36c564b6b1e0
MD5 1e6de6678d82edcc3dcb72afdcd26922
BLAKE2b-256 696355033ba8b5aae9e93009de947d956f247dd12204e9b86e77f1def70e07e0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tsfm_client-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82f2d96c0d01d5f7aa264bb6fa49c3a2de2486b618cf0dced39fab7fbeb822f2
MD5 adc81f499e856164216d1120005b40b3
BLAKE2b-256 c1c34cd96335735f2b4b5aff491fabf3516559d7cbfb7f27cb41cbee47a1c42b

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