STAT-API

Examples

Worked, copy-pasteable walkthroughs that assemble real datasets from the API — one set per sport.

NFL

Build an NFL box score

A box score is one game plus the per-player stat lines for both teams. Find a game in the current season, fetch its player stats, and group them by team.

Filter NFL games by season

List endpoints accept whitelisted filter parameters. This example resolves the current season from the API (so it survives the annual rollover) and uses it to filter games.

Hello, NFL

Every stat-api client reads its key from the STAT_API_KEY environment variable, so a first program is just: construct the client, call a list endpoint, and look at the rows.

Auto-paginate every NFL team

Every table exposes an auto-paging iterator that follows the next_from_id keyset cursor until it runs out — so you can consume a whole table without writing the paging loop.

Read an NFL player's game log

A game log is one player's per-game stat lines with the game context joined back in. Resolve the season, index its games by id, borrow a player from one game's box score, then page that player's stats and join each row to its game.

List a NFL team's roster

Grab a team to borrow its id, then list players filtered by team_id — the players endpoint accepts team_id as a filter for both NFL rosters.

Rank NFL season leaders

season_player_stats holds one row per player per season. Resolve the current season, page through all of it with the auto-pager, then sort client-side to build any leaderboard.

Build the NFL standings

season_team_stats has one row per team per season — wins, losses, games played. Resolve the current season, page the whole table, and sort by wins to build the standings.

NBA

Build an NBA box score

A box score is one game plus the per-player stat lines for both teams. Find a game in the current season, fetch its player stats, and group them by team.

Handle errors by type

The SDK maps status codes to typed errors — AuthenticationError (401), ValidationError (400), NotFoundError (404), QuotaExceededError (429). A 429 is a monthly budget, so it is never retried; branch on the type and handle each.

Filter NBA games by season

List endpoints accept whitelisted filter parameters. This example resolves the current season from the API (so it survives the annual rollover) and uses it to filter games.

Fetch one NBA team by id

Every table with a single-column primary key exposes a get(id) that returns exactly one row. Here we list one team to get a real id, then fetch it.

Hello, NBA

Every stat-api client reads its key from the STAT_API_KEY environment variable, so a first program is just: construct the client, call a list endpoint, and look at the rows.

Find Kalshi markets for an NBA game

Kalshi events point at the underlying game through a polymorphic (league_code, competition_id) pair — competition_id is the game's id. Resolve a game with the DSL, then use the code escape hatch to find its Kalshi event and list that event's markets.

Auto-paginate every NBA team

Every table exposes an auto-paging iterator that follows the next_from_id keyset cursor until it runs out — so you can consume a whole table without writing the paging loop.

Paginate by hand with from_id

Pagination is keyset, not offset. Each list response returns next_from_id — the cursor for the following page — and null on the last page. This is the loop the auto-paging iterator runs for you, written out by hand.

Read an NBA player's game log

A game log is one player's per-game stat lines with the game context joined back in. Resolve the season, index its games by id, borrow a player from one game's box score, then page that player's stats and join each row to its game.

Read your quota off a response

Every response is metered and stamped with X-Quota-Limit / X-Quota-Used / X-Quota-Remaining. The SDK parses them into a Quota on every list page, so you can watch your monthly budget without a second request.

Rolling averages over an NBA game log

A rolling average smooths a per-game stat over a trailing window. Fetch a player's game log with the ops, sort it oldest-first, then compute a 5-game trailing average of points — the windowed math the DSL leaves to the escape hatch.

Rank NBA season leaders

season_player_stats holds one row per player per season. Resolve the current season, page through all of it with the auto-pager, then sort client-side to build any leaderboard.

Build the NBA standings

season_team_stats has one row per team per season — wins, losses, games played. Resolve the current season, page the whole table, and sort by wins to build the standings.

MLB

NHL

PGA

DFS

General

Per-endpoint recipes

Every endpoint in the API reference ships runnable curl / JavaScript / TypeScript / Python snippets you can execute against the trial key in the browser. Jump straight to a league: