Skip to main content

Python client for the Synthefy API forecasting service

Project description

Synthefy Python Client

A Python client for the Synthefy API forecasting service. This package provides an easy-to-use interface for making time series forecasting requests.

Features

  • Simple API Client: Easy-to-use client for making forecasting requests
  • Pandas Integration: Built-in support for pandas DataFrames
  • Type Safety: Full type hints and Pydantic validation
  • Flexible Data Handling: Support for multiple data sources and metadata columns

Installation

pip install synthefy

Quick Start

Basic Usage

from synthefy import SynthefyAPIClient
import pandas as pd

# Initialize the client
client = SynthefyAPIClient(api_key="your_api_key_here")

# Or use environment variable
# export SYNTHEFY_API_KEY="your_api_key_here"
client = SynthefyAPIClient()

Making a Forecast Request

from synthefy import SynthefyAPIClient
from synthefy.data_models import ForecastV2Request
import pandas as pd

# Create sample data
history_data = {
    'timestamp': ['2024-01-01', '2024-01-02', '2024-01-03'],
    'sales': [100, 120, 110],
    'temperature': [20, 22, 21]
}

target_data = {
    'timestamp': ['2024-01-04', '2024-01-05', '2024-01-06'],
    'sales': [None, None, None],  # Values to forecast
    'temperature': [23, 24, 22]   # Known future values
}

history_df = pd.DataFrame(history_data)
target_df = pd.DataFrame(target_data)

# Create request using the convenience method
response = client.forecast_dfs(
    history_dfs=[history_df],
    target_dfs=[target_df],
    target_col='sales',
    timestamp_col='timestamp',
    metadata_cols=['temperature'],
    leak_cols=[],  # No leak columns in this example
    model='sfm_moe'
)

# response is a list of DataFrames with forecasts
forecast_df = response[0]
print(forecast_df)

Advanced Usage with Multiple Data Sources

# Multiple data sources
history_dfs = [history_df1, history_df2, history_df3]
target_dfs = [target_df1, target_df2, target_df3]

response = client.forecast_dfs(
    history_dfs=history_dfs,
    target_dfs=target_dfs,
    target_col='revenue',
    timestamp_col='date',
    metadata_cols=['marketing_spend', 'competitor_price'],
    leak_cols=['marketing_spend'],  # This column is known in the future
    model='sfm_moe'
)

# Each DataFrame in response corresponds to one data source
for i, forecast_df in enumerate(response):
    print(f"Forecast for data source {i}:")
    print(forecast_df)

API Reference

SynthefyAPIClient

The main client class for interacting with the Synthefy API.

Methods

  • forecast(request: ForecastV2Request) -> ForecastV2Response: Make a direct forecast request
  • forecast_dfs(...) -> List[pd.DataFrame]: Convenience method for working with pandas DataFrames

Parameters

  • api_key: Your Synthefy API key (can also be set via SYNTHEFY_API_KEY environment variable)
  • timeout: Request timeout in seconds (default: 120.0)

Configuration

Environment Variables

  • SYNTHEFY_API_KEY: Your Synthefy API key

Support

For support and questions:

License

MIT License - see LICENSE file for details.

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

synthefy-0.1.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

synthefy-0.1.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file synthefy-0.1.1.tar.gz.

File metadata

  • Download URL: synthefy-0.1.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for synthefy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3d17040452ba186dcff2ccb42ae7ddea61431c75bb643af8d844a471e7e1e527
MD5 2ae277a66c95c9f756d6688c7978d580
BLAKE2b-256 1e3dc794933169e1a9fbe3f6b0fdeca8e065fe6ebb23fc2c5837bf044b75fc59

See more details on using hashes here.

File details

Details for the file synthefy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: synthefy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for synthefy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e7f0c20eb2a61248da8676e6ec32d4829a17895e9bfe39aed487cf8afa67b93b
MD5 401fe8ef7b2e771f406c2222e607c76e
BLAKE2b-256 cdf9d284c995034f60b439f6f0143718398b0d99e216c3059a1db75e09fb54af

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