Skip to main content

Python SDK for FAIM time-series forecasting with foundation AI models

Project description

FAIM SDK

Python SDK for FAIM time-series forecasting with foundation AI models.

Installation

pip install faim-sdk

Quick Start

import numpy as np
from faim_sdk import ForecastClient, FlowStateForecastRequest
from faim_client.models import ModelName

# Initialize client
client = ForecastClient(
    base_url="http://localhost:8003",
    timeout=60.0
)

# Prepare your time-series data
# Shape: (batch_size, sequence_length, features)
data = np.random.randn(1, 100, 1).astype(np.float32)

# Create forecast request
request = FlowStateForecastRequest(
    x=data,
    horizon=10,
    model_version="1"
)

# Generate forecast
response = client.forecast(ModelName.FLOWSTATE, request)

# Access predictions
print(response.point)  # Shape: (batch_size, horizon, features)
print(response.metadata)  # Model metadata

Models

FlowState

Point forecasting model optimized for deterministic predictions.

from faim_sdk import FlowStateForecastRequest

request = FlowStateForecastRequest(
    x=data,
    horizon=10,
    model_version="1",
    output_type="point",  # Options: "point", "quantiles", "samples"
    scale_factor=1.0,  # Optional normalization
    prediction_type="mean"  # Options: "mean", "median", "quantile"
)

ToTo

Probabilistic forecasting model with quantile and sample-based predictions.

from faim_sdk import ToToForecastRequest

# Quantile predictions
request = ToToForecastRequest(
    x=data,
    horizon=10,
    model_version="1",
    output_type="quantiles",
    quantiles=[0.1, 0.5, 0.9]  # 10th, 50th, 90th percentiles
)

# Sample-based predictions
request = ToToForecastRequest(
    x=data,
    horizon=10,
    model_version="1",
    output_type="samples",
    num_samples=100
)

Response Format

All forecasts return a ForecastResponse object:

response = client.forecast(ModelName.TOTO, request)

# Access predictions based on output_type
if response.point is not None:
    predictions = response.point  # Shape: (batch_size, horizon, features)

if response.quantiles is not None:
    quantiles = response.quantiles  # Shape: (batch_size, horizon, num_quantiles)

if response.samples is not None:
    samples = response.samples  # Shape: (batch_size, horizon, num_samples)

# Access metadata
print(response.metadata)  # {'model_name': 'toto', 'model_version': '1'}

Async Usage

async with ForecastClient(base_url="http://localhost:8003") as client:
    response = await client.forecast_async(ModelName.FLOWSTATE, request)
    print(response.point)

Examples

See the examples/ directory for complete notebook examples:

  • flowstate_simple_example.ipynb - Point forecasting with FlowState
  • toto_simple_example.ipynb - Probabilistic forecasting with ToTo

Error Handling

The SDK provides specific exception types for different error scenarios:

from faim_sdk import (
    ModelNotFoundError,
    ValidationError,
    TimeoutError,
    NetworkError,
    SerializationError
)

try:
    response = client.forecast(ModelName.FLOWSTATE, request)
except ModelNotFoundError:
    print("Model or version not found")
except ValidationError:
    print("Invalid request parameters")
except TimeoutError:
    print("Request timed out")
except NetworkError:
    print("Network communication failed")
except SerializationError:
    print("Failed to serialize/deserialize data")

Configuration

Client Options

# Without authentication
client = ForecastClient(
    base_url="https://api.example.com",
    timeout=120.0,  # Request timeout in seconds
    verify_ssl=True,  # SSL certificate verification
    **httpx_kwargs  # Additional httpx.Client arguments
)

# With API key authentication
client = ForecastClient(
    base_url="https://api.example.com",
    api_key="your-secret-api-key",  # API key for authentication
    timeout=120.0,
    verify_ssl=True
)

Request Options

request = FlowStateForecastRequest(
    x=data,
    horizon=10,
    model_version="1",
    compression="zstd",  # Options: "zstd", "lz4", None
)

Requirements

  • Python >= 3.10
  • numpy >= 1.20.0
  • pyarrow >= 10.0.0
  • httpx >= 0.23.0

Development

Regenerating the Low-Level Client

The faim_client package is auto-generated from the OpenAPI specification. To regenerate after API changes:

# Get the latest OpenAPI spec from your server
curl http://your-server:8003/openapi.json > openapi.json

# Regenerate the client
openapi-python-client generate --path openapi.json --config client.config.yaml --meta none

The --meta none flag prevents creating an extra outer directory.

After regenerating, test that faim_sdk still works correctly:

poetry install
pytest tests/

License

Apache 2.0

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

faim_sdk-0.1.2.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

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

faim_sdk-0.1.2-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file faim_sdk-0.1.2.tar.gz.

File metadata

  • Download URL: faim_sdk-0.1.2.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.13 Darwin/24.6.0

File hashes

Hashes for faim_sdk-0.1.2.tar.gz
Algorithm Hash digest
SHA256 66b29dfcca4ce6beb0f44610dd98213cdaa2fb5c546e85bd9dc9c3c7be24fc36
MD5 64e2ab0f3d790754d261d7ff7ade89f7
BLAKE2b-256 908fd3c683430ff1b8f0cf78657af7d6b92fcfaa7feb3522e7d29200c4783537

See more details on using hashes here.

File details

Details for the file faim_sdk-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: faim_sdk-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.13 Darwin/24.6.0

File hashes

Hashes for faim_sdk-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d40b1f69c0b0139fa5ce3a05fc24b1f52aa764a2cb3a6c6d81be88e750ac7b11
MD5 a2c469be6338b0db54729f7633a8f5db
BLAKE2b-256 3472600bb868a129a3ad2e236224c370f6f83d095e8c578f564128d202d404ad

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