Skip to main content

Python SDK for the Geneva Forecasting Engine API

Project description

geneva-forecast

Forecast any time series in 3 lines of Python. A typed SDK for the Geneva Forecasting Engine — a high-performance time series forecasting API with automated model selection, conformal prediction intervals, and built-in charting.

Installation

pip install geneva-forecast

Quick Start

from geneva_forecast import GenevaClient

client = GenevaClient(
    api_url="https://api.roadmap-tech.com",
    api_key="gva_your_api_key_here",
)

# Monthly sales data (6 years)
monthly_sales = [
    112.0, 118.4, 132.1, 124.3, 121.1, 140.2,
    148.9, 153.7, 136.2, 119.0, 104.0, 118.5,
    121.3, 129.8, 138.5, 146.7, 128.4, 155.3,
    162.8, 149.1, 141.7, 119.5, 108.2, 126.3,
    133.9, 142.7, 156.1, 137.8, 145.2, 161.4,
    178.3, 168.0, 149.5, 125.3, 113.7, 132.8,
    139.5, 155.8, 148.2, 163.4, 152.7, 175.9,
    194.1, 181.3, 162.8, 140.6, 129.3, 148.7,
    157.2, 149.8, 171.6, 158.3, 168.9, 189.4,
    210.7, 195.2, 174.3, 153.1, 141.8, 163.9,
    172.4, 181.9, 195.7, 178.3, 183.5, 204.6,
    226.3, 213.8, 188.7, 165.4, 155.2, 179.8,
]

result = client.forecast(
    data=monthly_sales,
    horizon=12,
    wave_periods=[12],
)

for point in result.forecast:
    print(f"  Period {point.period}: {point.value:.2f}")

print(f"Model: {result.model_info.method_name}")
print(f"MAPE:  {result.metrics.mape:.2f}%")

The client can also be used as a context manager:

with GenevaClient(api_url="https://api.roadmap-tech.com", api_key="gva_...") as client:
    result = client.forecast(data=monthly_sales, horizon=12)

Prediction Intervals

Get conformal prediction intervals by setting confidence_level:

result = client.forecast(
    data=monthly_sales,
    horizon=12,
    confidence_level=0.95,
    include=["forecast", "prediction_intervals", "metrics", "model_info"],
)

for pt in result.prediction_intervals:
    print(f"  Period {pt.period}: {pt.forecast:.2f}  [{pt.lower:.2f}, {pt.upper:.2f}]")

Batch Forecasting

Forecast multiple time series in a single request:

result = client.batch_forecast(series=[
    {
        "id": "product_a",
        "data": [100, 120, 115, 130, 125, 140, 135, 150, 145, 160, 155, 170],
        "horizon": 6,
    },
    {
        "id": "product_b",
        "data": [200, 210, 205, 220, 215, 230, 225, 240, 235, 250, 245, 260],
        "horizon": 6,
    },
])

print(f"Batch: {result.successful}/{result.total_series} succeeded in {result.elapsed_ms:.0f}ms")

for sr in result.results:
    if sr.status == "success":
        values = [f"{p.value:.1f}" for p in sr.forecast.forecast]
        print(f"  {sr.id}: {', '.join(values)}")

Visualization

Built-in charting is included — no extra install needed:

from geneva_forecast.plot import plot_forecast

result = client.forecast(
    data=monthly_sales,
    horizon=12,
    confidence_level=0.95,
    include=["forecast", "fitted", "prediction_intervals", "metrics", "model_info"],
)

# One-liner chart with historical data, fitted values, forecast, and prediction intervals
plot_forecast(monthly_sales, result)

# Calendar date labels on x-axis (format: YYYY-MM-DD)
plot_forecast(monthly_sales, result, start_date="2020-01-01", freq="MS")
# Supported: "MS" (monthly), "QS" (quarterly), "W" (weekly),
#            "D" (daily), "H" (hourly), "YS" (yearly)

# Save to file
plot_forecast(monthly_sales, result, show=False, save="forecast.png")

Parameters

Parameter Type Default Description
data list[float] required Time series values (min 3, max 10,000)
method int | None None Forecasting method (0–9). None = auto-select best
wave_periods list[int] [12] Seasonal cycle lengths (e.g. [12] for monthly, [52] for weekly)
horizon int | None None Number of periods ahead to forecast
confidence_level float | None None Prediction interval confidence (e.g. 0.95)
include list[str] ["forecast", "metrics", "model_info"] Response sections to return

Available include Sections

"forecast" · "fitted" · "seasonal_factors" · "metrics" · "model_info" · "prediction_intervals" · "all"

Tip: Set method=None (the default) to let the Expert System automatically select the best-performing model for your data.

Error Handling

from geneva_forecast import GenevaAPIError, GenevaConnectionError, GenevaTimeoutError

try:
    result = client.forecast(data=[1.0, 2.0, 3.0])
except GenevaAPIError as e:
    print(f"API error {e.status_code}: {e.message}")
except GenevaTimeoutError:
    print("Request timed out")
except GenevaConnectionError:
    print("Could not connect to the Geneva API")

License

MIT

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

geneva_forecast-1.0.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

geneva_forecast-1.0.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file geneva_forecast-1.0.0.tar.gz.

File metadata

  • Download URL: geneva_forecast-1.0.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for geneva_forecast-1.0.0.tar.gz
Algorithm Hash digest
SHA256 03396a92f859bbac5cacf2372365dce6a722ab13b74e6aae07e262be18889914
MD5 e95b6f634c2f68dbd46b49cc615da60b
BLAKE2b-256 f6e2c5bc2b1655fa9e4a1b6f9cf78ba8c44505fed03232bff7f78bf359e92f68

See more details on using hashes here.

File details

Details for the file geneva_forecast-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for geneva_forecast-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2740031ddf3ae86fd6e6a93bbc7e411a446a1de8dc6f2a0d84f1f7e483793cc9
MD5 5d8969f0fcbb744fcab16fe1f79b6ce5
BLAKE2b-256 2b6db91f6e9cc32283ac4f75e47c64f436bd18833e85a47d995b62e7e2fd6870

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