Skip to content

Guides

Download historical NBA odds to CSV with Python

Pull NBA games and each sportsbook's opening and closing moneyline, spread and total into one CSV with pandas, add one game's line movement, and price a full season.

Every script run against the live API on December 4, 2026. One full run: 166 credits.

Searches for "historical NBA odds CSV" mostly land on old files with no source and no license. This tutorial builds the file yourself from the API: one row per game per sportsbook, with the opening and closing moneyline, spread and total, saved with pandas. It also pulls the line movement for one game, and shows what a full season costs in credits and how to stay under the 60 requests a minute limit.

Does DunkAPI allow a CSV download? Yes, for your own analysis. Save the rows to a CSV, load them in pandas, a spreadsheet or a database, and train and test models on them. What you may not do is publish or share that CSV, or pass it on, as a dataset, a feed or an API of its own. See usage rights and data timing and rights.

The example is a two-week range, November 3 to 16, 2025: 105 games on 14 game days, 8 sportsbooks, 840 rows. One full run costs 166 credits: 16 for the games, 140 for the odds (10 a game day) and 10 for one game's line movement. A whole regular season costs 1,644 credits, and the 500 free credits cover about 48 game days of odds. Prices here are market information: the tutorial does not work out stakes or payouts and does not recommend a bet.

1. Install the client and set your key

The client has no required dependencies. This tutorial uses pandas for the tables. It needs Python 3.9 or newer, and the client reads your key from DUNKAPI_API_KEY.

pip install "dunkapi[pandas]"
export DUNKAPI_API_KEY=your_key_here

2. Pull the games in a date range

list_games returns finished games with their final scores, 200 to a page and 2 credits a page. from_ and to take dates (US Eastern), so the same call pulls a week, a month or a season; for a whole season use season=2025 instead (seasons are named by the year they end, so 2025 is 2024-25). The odds call in the next step goes by day, so this step also gives you the list of game days.

import pandas as pd
from dunkapi import Client

client = Client()  # reads DUNKAPI_API_KEY

# Finished regular-season games in a date range, 200 a page and 2 credits a page.
FROM, TO = "2025-11-03", "2025-11-16"
rows, offset = [], 0
while offset is not None:
    page = client.list_games(season_type="regular", status="final", from_=FROM, to=TO, limit=200, offset=offset)
    rows += page["games"]
    offset = page.get("next_offset")

games = pd.json_normalize(rows).rename(columns={
    "home.abbrev": "home", "home.score": "home_pts", "away.abbrev": "away", "away.score": "away_pts",
})[["game_id", "date", "home", "home_pts", "away", "away_pts"]].sort_values(["date", "game_id"])
games.to_csv("games.csv", index=False)

days = sorted(games["date"].unique())
print(len(games), "games on", len(days), "game days,", days[0], "to", days[-1])
print(games.head(3).to_string(index=False))
print("credits left:", client.last_credits_remaining)

Output

105 games on 14 game days, 2025-11-03 to 2025-11-16
  game_id       date home  home_pts away  away_pts
401810011 2025-11-03  BKN       109  MIN       125
401810012 2025-11-03  IND       115  MIL       117
401810013 2025-11-03  BOS       103 UTAH       105
credits left: 1191

The last line is the credit balance of the key that ran it; yours will differ. The 105 games fit on one page, so this step cost 2 credits.

3. Pull each game day's odds and write the CSV

get_odds with a date returns every game that day with each sportsbook's opening and closing moneyline, spread and total. A day costs 10 credits whatever the number of games; asking game by game would cost 5 each. The script saves every day to odds_raw.json as it goes, so a rerun skips days you already paid for, and it waits between calls to stay under the 60 requests a minute limit.

It then flattens the result to one row per game per sportsbook. Moneylines are American odds. A spread is the home team's: 9.5 means the home team gets 9.5 points (it is the underdog) and -3.5 means it gives 3.5.

import json, os, time
import pandas as pd
from dunkapi import Client

client = Client()
games = pd.read_csv("games.csv", dtype={"game_id": str})
days = sorted(games["date"].unique())
print(len(days), "game days x 10 credits =", len(days) * 10, "credits")

# One call a day returns every game that day with each sportsbook's open and close.
# Saved as it goes, so a rerun skips days you already paid for.
cache = json.load(open("odds_raw.json")) if os.path.exists("odds_raw.json") else {}
for day in days:
    if day not in cache:
        cache[day] = client.get_odds(date=day)["games"]
        json.dump(cache, open("odds_raw.json", "w"))
        time.sleep(1.1)  # 60 requests a minute is the limit

# One row per game per sportsbook.
rows = []
for day_games in cache.values():
    for g in day_games:
        if g["status"] != "final":
            continue
        for b in g["books"]:
            rows.append({
                "game_id": g["game_id"], "date": g["date"],
                "home": g["home"]["abbrev"], "away": g["away"]["abbrev"],
                "home_pts": g["home"]["score"], "away_pts": g["away"]["score"],
                "book": b["provider"],
                "home_ml_open": b["home_ml_open"], "home_ml_close": b["home_ml_close"],
                "away_ml_open": b["away_ml_open"], "away_ml_close": b["away_ml_close"],
                "home_spread_open": b["home_spread_open"], "home_spread_close": b["home_spread_close"],
                "total_open": b["total_open"], "total_close": b["total_close"],
            })
odds = pd.DataFrame(rows)
odds.to_csv("nba_odds_2025-11-03_to_2025-11-16.csv", index=False)

print(len(odds), "rows,", odds["game_id"].nunique(), "games,", odds["book"].nunique(), "books")
print(odds.groupby("game_id").size().describe()[["min", "50%", "max"]].to_string())
print(odds.drop(columns=["date", "home_pts", "away_pts"]).head(3).to_string(index=False))
print("credits left:", client.last_credits_remaining)

Output

14 game days x 10 credits = 140 credits
840 rows, 105 games, 8 books
min    8.0
50%    8.0
max    8.0
  game_id home away      book  home_ml_open  home_ml_close  away_ml_open  away_ml_close  home_spread_open  home_spread_close  total_open  total_close
401810011  BKN  MIN    BetMGM         275.0          340.0        -350.0         -450.0               8.5                9.5       229.5       226.5
401810011  BKN  MIN BetOnline           NaN          334.0           NaN         -425.0               9.0               10.0       229.0       226.0
401810011  BKN  MIN    Bovada         300.0          335.0        -400.0         -450.0               9.0                9.5       229.0        226.0
credits left: 1051

Every one of the 105 games has all 8 sportsbooks. The file is saved as nba_odds_2025-11-03_to_2025-11-16.csv with the game, the final score and 8 odds columns on each row. Some cells are empty: BetOnline's first row has no opening moneyline, so the CSV has a blank there (pandas reads it as NaN). Keep the blanks rather than filling them. Lines are held from July 2020 with opening and closing per book; before that each book has one final pregame line.

This CSV is for your own analysis. Do not post it, attach it to a repository or share it as a dataset.

4. Check the file: how far lines moved between open and close

Read the CSV back and summarize it. The first table counts, for each sportsbook, how many rows have an opening moneyline and how far its totals and spreads moved on average. The second takes the median across books for each game.

import pandas as pd

odds = pd.read_csv("nba_odds_2025-11-03_to_2025-11-16.csv", dtype={"game_id": str})
odds["total_move"] = odds["total_close"] - odds["total_open"]
odds["spread_move"] = odds["home_spread_close"] - odds["home_spread_open"]

# Per book: how many rows have an opening moneyline, and how far totals and spreads moved.
by_book = odds.groupby("book").agg(
    games=("game_id", "size"),
    open_ml=("home_ml_open", "count"),
    avg_total_move=("total_move", "mean"),
    avg_spread_move=("spread_move", "mean"),
).round(2)
print(by_book.to_string())

# Per game: the median across books at the open and at the close.
per_game = odds.groupby(["game_id", "date", "home", "away"]).agg(
    spread_open=("home_spread_open", "median"), spread_close=("home_spread_close", "median"),
    total_open=("total_open", "median"), total_close=("total_close", "median"),
).reset_index()
per_game["total_move"] = per_game["total_close"] - per_game["total_open"]
print(per_game.sort_values("total_move").iloc[[0, -1]].to_string(index=False))
print("games where the median total moved:", int((per_game["total_move"] != 0).sum()), "of", len(per_game))

Output

                                  games  open_ml  avg_total_move  avg_spread_move
book                                                                             
BetMGM                              105      105           -0.31             0.20
BetOnline                           105       18           -0.49            -0.04
Bovada                              105      103           -0.41             0.10
DraftKings                          105      105           -0.10             0.17
FanDuel                             105      105           -0.36             0.33
MyBookie                            105      105           -0.26             0.27
Pinnacle                            105      105           -0.44             0.12
theScore Bet (formerly ESPN BET)    105      105           -0.14             0.29
  game_id       date home away  spread_open  spread_close  total_open  total_close  total_move
401810018 2025-11-03  POR  LAL         -3.5          -9.5      234.00        228.0       -6.00
401809780 2025-11-07  SAC  OKC         10.0          11.5      227.75        234.5        6.75
games where the median total moved: 96 of 105

BetOnline has an opening moneyline on only 18 of its 105 rows and Bovada on 103, so a moneyline move computed across books uses different books at the open and the close. Average totals fell between open and close at every book, by 0.10 to 0.49 points, and the median total moved in 96 of the 105 games. This is two weeks of one month, so read it as a description of the file, not a rule about the market.

5. Add the line movement for one game

get_odds gives the open and the close. get_line_movement gives every capture in between for one game: our snapshots of each sportsbook's moneyline, spread and total, taken about once a day and every hour for games in the next four days, and one game costs 10 credits. Pass provider for one sportsbook, or leave it out for all of them. A capture identical to the one before it is left out. This is Minnesota at Brooklyn on November 3 (scheduled start 00:00 UTC on November 4), DraftKings.

import pandas as pd
from dunkapi import Client

client = Client()

# One game, one book: every capture we hold before tip-off. 10 credits.
game_id = "401810011"  # Minnesota at Brooklyn, 2025-11-03
move = client.get_line_movement(game_id, provider="DraftKings")
snaps = pd.DataFrame(move["movement"]["DraftKings"])
snaps.to_csv("line_movement_401810011_DraftKings.csv", index=False)

print(len(snaps), "captures")
print(snaps.to_string(index=False))
print("credits left:", client.last_credits_remaining)

Output

10 captures
             captured_at  home_ml  away_ml  home_spread  total
2025-11-03T00:50:38.000Z      285     -360          8.5  229.5
2025-11-03T11:55:37.000Z      310     -395          8.5  228.5
2025-11-03T12:25:37.000Z      295     -375          8.5  229.5
2025-11-03T12:55:37.000Z      295     -375          8.5  227.5
2025-11-03T14:55:37.000Z      295     -375          8.5  226.5
2025-11-03T19:55:38.000Z      295     -375          8.5  227.5
2025-11-03T22:25:37.000Z      310     -395         10.5  225.5
2025-11-03T22:55:37.000Z      330     -425          9.5  225.5
2025-11-03T23:50:38.000Z      330     -425         10.5  226.5
2025-11-03T23:55:38.000Z      330     -425          9.5  226.5
credits left: 1041
DraftKings total for Minnesota at Brooklyn, every capture before tip-off, Nov 3 2025
220.0222.5225.0227.5230.0232.5Capture time on Nov 3 (UTC)Total11:5512:5519:5522:5523:55Total, 00:50: 229.5Total, 11:55: 228.5Total, 12:25: 229.5Total, 12:55: 227.5Total, 14:55: 226.5Total, 19:55: 227.5Total, 22:25: 225.5Total, 22:55: 225.5Total, 23:50: 226.5Total, 23:55: 226.5

10 captures, times in UTC. The first (229.5) matches the opening total in the CSV and the last (226.5) matches the closing total.

The home moneyline went from +285 to +330 and the home spread from 8.5 to 9.5, while the total slid from 229.5 to 226.5, with a low of 225.5. The first and last captures match DraftKings' open and close in the CSV. The spread flips between 10.5 and 9.5 in the last hour: captures are snapshots of what the book showed at that moment. This is the same data as the line movement recipe, one game at a time.

6. What a full season costs, and how to stay under the rate limit

Count the game days before you pay for the odds. The odds call is 10 credits a game day, so the cost is the number of days with games times 10, plus 2 credits for each 200 games listed. This script lists the whole 2024-25 regular season (7 pages, 14 credits) and prices it. The 500 free credits fill from the first game day forward.

The limit is 60 requests a minute. The loop in step 3 sleeps 1.1 seconds after each call, which is under 55 requests a minute, so a season of 163 days takes about three minutes (163 x 1.1 seconds). If you do hit the limit the client waits for the time the server asks and retries before it raises RateLimitError. Because the script saves every day as it goes, a stopped run resumes without paying twice.

import pandas as pd
from dunkapi import Client

client = Client()

# Count a whole regular season's game days before paying for the odds. 2025 = 2024-25. 7 pages, 14 credits.
rows, offset = [], 0
while offset is not None:
    page = client.list_games(season=2025, season_type="regular", status="final", limit=200, offset=offset)
    rows += page["games"]
    offset = page.get("next_offset")
days = sorted({g["date"] for g in rows})

pages = -(-len(rows) // 200)
print(len(rows), "games on", len(days), "game days,", days[0], "to", days[-1])
print("games:", pages * 2, "credits | odds:", len(days) * 10, "credits | total:", pages * 2 + len(days) * 10)

free = 500
affordable = (free - pages * 2) // 10
print("free 500 credits: after the season's games,", affordable, "game days of odds; the", str(affordable) + "th is", days[affordable - 1])
print("credits left:", client.last_credits_remaining)

Output

1230 games on 163 game days, 2024-10-22 to 2025-04-13
games: 14 credits | odds: 1630 credits | total: 1644
free 500 credits: after the season's games, 48 game days of odds; the 48th is 2024-12-10
credits left: 1027
  • A season: 1,644 credits: 14 for the 1,230 games plus 1,630 for the 163 game days of odds. Add 10 for each game whose movement you want.
  • The free 500 credits: about 48 game days of odds, which in 2024-25 reaches December 10, the first seven weeks of the season. The two-week run in this tutorial is 166 credits.
  • Cheaper: pull only the days you need, or one game at 5 credits when you want one game's odds without the rest of the day.

Keep the CSV for your own work. If you later want to share results, share what you derived (a model, a chart, a summary) and not the rows.

Tools and credits

  • list_games: 8 calls, 16 credits.
  • get_odds: 14 calls, 140 credits (10 credits for every game day: a day's games cost 10, one game costs 5).
  • get_line_movement: 1 call, 10 credits.

One full run: 166 credits.

What you can do with the data

You may store these rows in a CSV or a database for your own analysis, train models and backtest on them, and build products that show your users what you derive. You may not publish, share or redistribute the CSV, or the prices, as a raw file, feed or dataset, or an API of its own. Lines and prices are market information. This tutorial does not size, price or recommend a wager, and it links to no sportsbook.

Details: data timing and rights.

What to do next

Start with 500 free credits every month

No card. pip install dunkapi, REST or MCP.