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.app",
)

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.0.tar.gz (8.8 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.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: first_forecast-0.1.0.tar.gz
  • Upload date:
  • Size: 8.8 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.0.tar.gz
Algorithm Hash digest
SHA256 29d320e947fa9bf7e2eab68b39960e32e71ddf4b3d93d1e08cdeaef2fedb5586
MD5 5e44e1ca59d2623d95357a9fd0d0df39
BLAKE2b-256 faa5185d5ebb1b492c3f2d79a8ac2d420377794192c4fb829556efba5b1c01b8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: first_forecast-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 503f02cba10db6eb408d2650d7b47ad959f7f3e8439b3f02eb57b60ed424c3b3
MD5 cdfad2c9fd045b43ea74e2f846f2326a
BLAKE2b-256 da6dd308431c6292657bef0c432790ef07e518caa97fbd756faed24bae77eea3

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