Skip to main content

Python SDK for Snowtrail Research API - commodities intelligence for systematic trading.

Project description

Snowtrail Python SDK

Python SDK for the Snowtrail Research API - commodities intelligence for systematic trading.

Installation

pip install snowtrail

Verify your setup:

python -m snowtrail.check_setup

Quick Start

from snowtrail import Snowtrail

# Initialize the client (uses SNOWTRAIL_API_KEY env var if set)
client = Snowtrail(api_key="your-api-key")

# Get latest GBSI-US system stress signal
df = client.gbsi_us.system_stress()
print(df)

# Get historical data
df = client.gbsi_us.system_stress(
    start="2024-01-01",
    end="2024-12-31",
    limit=500
)

All endpoints return a pandas DataFrame by default.

Client Overview

The SDK is a thin wrapper around the REST API with no business logic:

  • Typed accessors for each product (client.gbsi_us, client.pemi, etc.)
  • DataFrame responses for easy analysis and backtesting
  • Automatic retries with exponential backoff for transient errors
  • Environment-based auth via SNOWTRAIL_API_KEY

The client maps directly to API endpoints - what you see in the API docs is what you get.

Authentication

Set your API key via environment variable (recommended):

export SNOWTRAIL_API_KEY="your-api-key"
from snowtrail import Snowtrail

# Automatically uses SNOWTRAIL_API_KEY
client = Snowtrail()
df = client.gbsi_us.system_stress()

Or pass it directly:

client = Snowtrail(api_key="your-api-key")

Products

Product Description Primary Signal Frequency
gbsi_us US Natural Gas Balance Stress Index system_stress() Weekly
gbsi_eu EU Natural Gas Balance Stress Index system_stress() Daily
pemi Power Event Market Intelligence power_stress() Event-driven
glmi Global LNG Market Intelligence lng_stress() Monthly
wrsi Weather Risk Signal Intelligence weather_risk() 4x daily
wssi_us Weather Storage Shock Index weather_shock() 4x daily

Return Types

All data endpoints return a pandas DataFrame by default:

df = client.gbsi_us.system_stress()
# Returns: pandas.DataFrame with columns like week_ending, stress_regime, etc.

For raw JSON responses (including metadata), use _get_raw():

response = client.gbsi_us._get_raw("system_stress", latest=True)
# Returns: {"product_id": "gbsi_us", "table": "...", "data": {...}, "metadata": {...}}

Usage Examples

GBSI-US (US Natural Gas)

# Signals
df = client.gbsi_us.system_stress()

# Features
df = client.gbsi_us.balance_momentum()
df = client.gbsi_us.storage_inventory()
df = client.gbsi_us.supply_elasticity()
df = client.gbsi_us.features()

# Events
df = client.gbsi_us.storage_surprise()
df = client.gbsi_us.regime_shift()

GBSI-EU (EU Natural Gas)

# Filter by country
df = client.gbsi_eu.system_stress(country="DE")
df = client.gbsi_eu.composite(country="NL")
df = client.gbsi_eu.dispersion()

WRSI (Weather Risk)

# Filter by geography
df = client.wrsi.weather_risk(geography="US")
df = client.wrsi.forecast_dynamics(region_type="state")

Historical Data

All endpoints support date range queries:

# Get history instead of latest
df = client.gbsi_us.system_stress(
    latest=False,
    start="2023-01-01",
    end="2024-01-01",
    limit=1000
)

Retries and Timeouts

The SDK handles transient failures automatically:

  • Retried errors: 429 (rate limit), 500, 502, 503, 504
  • Retry attempts: 3 with exponential backoff (1s, 2s, 4s)
  • Default timeout: 30 seconds per request
  • Respects Retry-After header when present
# Custom timeout
client = Snowtrail(api_key="...", timeout=60)

Error Handling

from snowtrail import Snowtrail, AuthenticationError, RateLimitError, NotFoundError, APIError

client = Snowtrail(api_key="your-api-key")

try:
    df = client.gbsi_us.system_stress()
except AuthenticationError:
    print("Invalid API key")
except RateLimitError:
    print("Rate limit exceeded after retries")
except NotFoundError:
    print("Endpoint not found")
except APIError as e:
    print(f"API error: {e}")

Low-Level Access

For direct API access, use the underlying HTTP client:

# Direct GET request (returns raw dict)
response = client._client.get("/gbsi_us/system_stress", params={"latest": True})

# Health check
client.health()  # {"status": "ok"}

# List all products
client.products()  # [{"id": "gbsi_us", "name": "GBSI-US", ...}, ...]

The client includes a User-Agent header (snowtrail-python/{version}) for debugging.

Examples

See the examples/ directory for Jupyter notebooks:

  • 01_quickstart.ipynb - Basic SDK usage and product exploration
  • 02_signal_analysis.ipynb - Signal analysis and visualization workflows

API Reference

Support

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

snowtrail-0.1.2.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

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

snowtrail-0.1.2-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: snowtrail-0.1.2.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for snowtrail-0.1.2.tar.gz
Algorithm Hash digest
SHA256 dbced9baf4d64a5fb44ba69110108ef672a2468ee96d11d4083d2962df3f4743
MD5 e9b3acf2c933725f214d3e3705879a5c
BLAKE2b-256 9a8f92f17ecd5174c0575c90fd81eaacb53d541c69c4632d006c54ca630106cf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: snowtrail-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for snowtrail-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d733f0f57d54f039c8dd9e74b00cbd1ffc3e8beeebfd6335576f6348be55127a
MD5 59dbf87ebfcb4cbefdef845019c198ec
BLAKE2b-256 0776087a7161a998c0c0e7d414d5b63c4250c130f4a3f8dafec7db2cfe963800

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