Skip to main content

Official Python SDK for the First Forecast B2B2C API.

Project description

first-forecast

Official Python SDK for the First Forecast B2B2C API.

pip install first-forecast

Quick start (sync)

import os

from first_forecast import FirstForecast

ff = FirstForecast(api_key=os.environ["FF_API_KEY"])  # ff_live_... or ff_test_...

result = ff.forecast("AAPL", persona="balanced")
print(result["compliance"]["jurisdiction"])  # 'US'
print(result["forecast"]["horizons"][0]["most_probable"])

Quick start (async)

import asyncio

from first_forecast import AsyncFirstForecast


async def main():
    async with AsyncFirstForecast(api_key=...) as ff:
        result = await ff.forecast("AAPL", jurisdiction="EU")
        print(result["compliance"]["rules_applied"])


asyncio.run(main())

Sandbox

ff = FirstForecast(
    api_key=os.environ["FF_SANDBOX_KEY"],            # ff_test_<...>
    base_url="https://api-sandbox.first-forecast.com",
)

Methods

Method Endpoint
ff.forecast(ticker, ...) GET /v1/forecast/{ticker}
ff.multi(tickers, ...) GET /v1/multi
ff.tickers(...) GET /v1/tickers
ff.usage() GET /v1/usage

The SSE stream endpoint (/v1/forecast/{ticker}/stream) is not bundled — use httpx-sse or aiohttp directly.

Errors

from first_forecast import FirstForecast, FirstForecastError

try:
    ff.forecast("NOTAREAL")
except FirstForecastError as e:
    if e.kind == "auth":         # 401 / 403
        ...
    elif e.kind == "not_found":  # 404
        ...
    elif e.kind == "bad_request":
        ...
    elif e.kind == "rate_limited":
        wait = e.retry_after or 5
        ...
    elif e.kind == "server_error":
        ...
    elif e.kind == "network":    # httpx.HTTPError
        ...
    elif e.kind == "parse":      # server returned non-JSON
        ...
    print(e.status, e.body)

Versioning

Tracks packages/schemas/openapi.yml in the first-forecast monorepo. Major-version bumps indicate a breaking change to that contract.

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

first_forecast-0.1.2.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

first_forecast-0.1.2-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for first_forecast-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0b390125a2a72949dba93b9b578ccd585bd007c15ed450c571edb23c98430c9d
MD5 e4696a58f588e3b31bef5692e1597c70
BLAKE2b-256 f357a519016f04b49af661ab769e8d06319354ebb2821f28227cfa3da25bc1ee

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for first_forecast-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2756c62bf217460e1da08a28c5714d19752e7deaa709d93d354eabd7748fc08f
MD5 c32e94660f197338a123bf6ee857dd46
BLAKE2b-256 c49e76d2c5ba97fb752513f83f7b5137987537e26dfe15631a64c72b6e21579d

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