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-clientQuickstart
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
- api.<league>.<table>.list(**params)
- api.<league>.<table>.get(id)
- for row in api.<league>.<table>.iter(**params):
- api.nfl.weeks(season=...)
- api.sim.nfl.run(game_id=..., n_draws=..., seed=..., include=..., **overrides)
- api.nba.weeks(season=...)
- api.sim.nba.run(game_id=..., n_draws=..., seed=..., include=..., **overrides)
- api.dfs.slates.optimizer_lineups(slate_id, req) # defaults to mode="fast"
- api.dfs.slates.optimizer_lineups_csv(slate_id, req)
- 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.
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/lineupsandPOST /dfs/contests/{contest_id}/optimizer/lineupsdefault tomode: "sim"+strategy: "optimal", returning correlatedgames[].scenarios[]and live NFL/NBAgames[].correlations(override per-game weights or add custom branches withscenarios[]). Explicit caller overrides always win over strategy defaults. CalloptimizerLineupsto run synchronousmode: "fast"MILP. - Synchronous vs. background 202 polling:
simLineupsandcontests.buildLineupspoll202 Acceptedjobs automatically viaGET /api/v1/dfs/jobs/{job_id}(respectingRetry-After), or acceptwait: trueto sendPrefer: waitfor inline completion. UsesimLineupsStart+simJobto manage non-blocking queues explicitly. - Instant pool_id re-selection: read
sim.versions.pool_idfrom any completed build and pass it tosimSelectPoolwith updatedscenarios[], diversity weights, exposure bounds, orinclude_diversity_frontier: truewithout 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.