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.4.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.4-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: synthefy-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 0f2a5efd4559c78900414e4592c841e246c9ce970db2268640fadc2c9a2d9bad
MD5 e7eb180ff030cdf7c26c85a298324275
BLAKE2b-256 95196dc5832a4eb32b3cd27776cc4c853c72011442d937cfce0387c05033e3f7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: synthefy-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b6c2c9e5a8ab6ab6f1158a87b8e2791a99f67964a1a803504af75e5a6cb9f3e8
MD5 ae224ff84afa0107a1756fa514224c25
BLAKE2b-256 82b0520ba707a90a7b0f6270462cae59472e226ad06481bd9ada10bf5a8ac625

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