STAT-API

Python SDK

The official STAT-API client for Python. A typed wrapper over the REST surface, SIM engines, and DFS optimizers — construct StatApi and every request and response is statically typed. Version v0.3.1.

Install

pip install stat-api-client

Quickstart

Construct StatApi with STAT_API_KEY set, list rows, and print them.

# Hello, NBA
# Generated from schema/api/examples/hello-stat-api.yml — do not edit.
from statapi import StatApi
import json

api = StatApi()  # reads STAT_API_KEY from the environment

# List a few teams
teams = api.nba.teams.list(limit=3).rows

# Print what came back
print(json.dumps(teams, indent=2, default=str))

Client method reference

Tables & auto-paging
  • api.<league>.<table>.list(**params)
  • api.<league>.<table>.get(id)
  • for row in api.<league>.<table>.iter(**params):
NFL Play-by-Play SIM (beta)
  • api.nfl.weeks(season=...)
  • api.sim.nfl.run(game_id=..., n_draws=..., seed=..., include=..., **overrides)
NBA Possession SIM (beta)
  • api.nba.weeks(season=...)
  • api.sim.nba.run(game_id=..., n_draws=..., seed=..., include=..., **overrides)
DFS Fast Optimizer & Late Swap (mode="fast")
  • api.dfs.slates.optimizer_lineups(slate_id, req) # defaults to mode="fast"
  • api.dfs.slates.optimizer_lineups_csv(slate_id, req)
DFS SIM Lineups, Scenarios, Pool Re-Select & Async Jobs
  • api.dfs.slates.sim_lineups(slate_id, req, wait=True) # default mode="sim" + strategy="optimal"
  • api.dfs.contests.build_lineups(contest_id, req, wait=True)
  • api.dfs.slates.sim_lineups_csv(slate_id, req, wait=...)
  • api.dfs.slates.sim_lineups_start(slate_id, req)
  • api.dfs.slates.sim_job(slate_id, job_id) # GET /api/v1/dfs/jobs/{job_id}
  • api.dfs.slates.sim_select_pool(slate_id, req)
  • api.dfs.slates.sim_late_swap(slate_id, req, wait=...)

SIM & Optimizer starter templates

Copy-pasteable runnable templates generated from the same YAML specs as the cookbook, verified to produce identical output across all 4 languages.

Run your first NFL game simulationOpen full recipe & verified output →
from statapi import StatApi

api = StatApi()  # reads STAT_API_KEY from the environment

# Find the free game
weeks = api.nfl.weeks(season=2026)
game_id = weeks["free_game_id"]
print(f"Season {weeks['season']} | free game {game_id} | {len(weeks['games'])} games")

# Run the game 5,000 times
run = api.sim.nfl.run(
    game_id=game_id,
    n_draws=5000,
    seed=42,
    include={
        "summary": True,
        "distributions": False,
        "scorebox": False,
        "pbp": False,
    },
)
summary = run["output"]["summary"]
if summary is None:
    raise RuntimeError("the run returned no summary")
print(
    f"Simulated total {summary['sim_total_mean']:.2f} (SD {summary['sim_total_sd']:.2f}) | "
    f"home win {summary['home_win_prob'] * 100:.1f}% | "
    f"home cover {summary['home_cover_prob'] * 100:.1f}% | "
    f"over {summary['over_prob'] * 100:.1f}%"
)
print(f"Box-score checks: {'passed' if summary['conservation_ok'] else 'failed'}")

# Rank the players
top = sorted(summary["players"], key=lambda p: p["rec_yd_mean"], reverse=True)[:5]
print("Top 5 players by mean receiving yards:")
for p in top:
    print(
        f"  Player {p['player_id']} ({p['position']}/{p['depth_role']}) | "
        f"mean {p['rec_yd_mean']:.1f} | median {p['rec_yd_p50']:.1f} | "
        f"90th percentile {p['rec_yd_p90']:.1f}"
    )

Unified modes, scenarios, async 202 jobs & <50ms pool re-selection

  • Zero-param optimal SIM & execution modes: both POST /dfs/slates/{slate_id}/optimizer/lineups and POST /dfs/contests/{contest_id}/optimizer/lineups default to mode: "sim" + strategy: "optimal", returning correlated games[].scenarios[] and live NFL/NBA games[].correlations (override per-game weights or add custom branches with scenarios[]). Explicit caller overrides always win over strategy defaults. Call optimizerLineups to run synchronous mode: "fast" MILP.
  • Synchronous vs. background 202 polling: simLineups and contests.buildLineups poll 202 Accepted jobs automatically via GET /api/v1/dfs/jobs/{job_id} (respecting Retry-After), or accept wait: true to send Prefer: wait for inline completion. Use simLineupsStart + simJob to manage non-blocking queues explicitly.
  • Instant pool_id re-selection: read sim.versions.pool_id from any completed build and pass it to simSelectPool with updated scenarios[], diversity weights, exposure bounds, or include_diversity_frontier: true without re-simulating draws.
  • Direct operator CSV strings: call the CSV helper (e.g. api.dfs.slates.optimizer_lineups_csv(slate_id, req)) to receive ready-to-upload rows preserving Entry IDs on late swap.

Authentication, pagination & errors

Reads STAT_API_KEY automatically (default base URL https://api.stat-api.com). Get a key on the pricing page.

Table endpoints return bounded pages with next_from_id or stream all rows via iter(). HTTP failures raise typed StatApiError subclasses (AuthenticationError 401, PlanRequiredError 402, ValidationError 400, NotFoundError 404, QuotaExceededError 429) with Quota counts from X-Quota-* headers.

Free SIM games: NFL 43418 (2026 Week 1 DEN @ KC) and NBA 6029936 (DET @ BOS); other games require a Pro or Elite plan, or the DFS add-on.