Skip to content

Guides

NBA player props history in Python

Pull a season of one NBA player's prop lines with the result of every game, then add line movement, no-vig probabilities and a backtest with its interval.

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

Most props code shows today's lines. This tutorial goes the other way: a full season of one player's points lines, each joined to what he scored, so you can see how the line and the result compare game by game.

The example is Shai Gilgeous-Alexander's 2025-26 regular season. The same calls work for any NBA player and for rebounds, assists, threes, blocks, steals and the combo markets. One full run costs 76 credits: 1 for the player search, 30 for the season of lines, 10 each for one game's movement and probabilities, and 25 for the backtest.

1. Install the client and set your key

The client has no required dependencies. This tutorial uses pandas for the tables and matplotlib for the chart. The client reads your key from DUNKAPI_API_KEY.

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

2. Pull a season of lines and results

search_players finds the player id. get_prop_history returns one row per game: the closing line (the median across books), the opening line, the prices at the close, what he recorded from our box scores, and the result against the line. It takes up to 200 games a call and costs 10 credits for every 25 games already played that the call covers, so this 69-game season costs 30.

import pandas as pd
from dunkapi import Client, to_dataframe

client = Client()  # reads DUNKAPI_API_KEY

player = client.search_players("Gilgeous-Alexander", limit=1)["players"][0]
history = client.get_prop_history(
    player["player_id"],
    "player_points",
    from_date="2025-10-01",
    to_date="2026-04-15",
    limit=200,
)
df = to_dataframe(history, key="games")
df["moved"] = df["line"] - df["open_line"]
df.to_csv("sga_points_props_2025_26.csv", index=False)

print(player["name"], player["player_id"])
print(history["summary"])
print(df[["game_date", "open_line", "line", "actual", "result", "margin"]].head(5).to_string(index=False))
print("credits left:", client.last_credits_remaining)

Output

Shai Gilgeous-Alexander 4278073
{'games': 69, 'graded': 68, 'overs': 28, 'unders': 40, 'pushes': 0, 'over_rate': 0.412, 'avg_line': 31.2, 'avg_actual': 31.1}
 game_date  open_line  line  actual result  margin
2025-10-21       32.5  32.5    35.0   over     2.5
2025-10-23       32.5  32.5    55.0   over    22.5
2025-10-25       33.5  33.5    30.0  under    -3.5
2025-10-27       32.5  32.5    23.0  under    -9.5
2025-10-28       32.5  33.5    31.0  under    -2.5
credits left: 3772

The last line is the credit balance of the key that ran it; yours will differ. 69 games had a line and 68 have a result: the Feb 4 game has a line but no result in our box scores. margin is points scored minus the line. His average line (31.2) and average points (31.1) were a tenth of a point apart; he went over in 28 of 68 games (41.2%).

3. Line against result, game by game

import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv("sga_points_props_2025_26.csv").dropna(subset=["actual"])
ax = df.plot(x="game_date", y=["line", "actual"], marker="o", figsize=(10, 4), rot=45)
ax.set_ylabel("Points")
ax.legend(["Closing line", "Points scored"])
plt.tight_layout()
plt.savefig("sga_points_vs_line.png", dpi=150)
Shai Gilgeous-Alexander, points against the closing line, 2025-26 regular season
  • Closing line
  • Points scored
10.020.030.040.050.060.0Game date (month-day)Points10-2711-1111-2812-2201-0501-2303-0403-2304-08Closing lineClosing line, 10-21: 32.5Closing line, 10-23: 32.5Closing line, 10-25: 33.5Closing line, 10-27: 32.5Closing line, 10-28: 33.5Closing line, 10-30: 33.5Closing line, 11-02: 31.5Closing line, 11-04: 30.5Closing line, 11-05: 32.5Closing line, 11-07: 31.5Closing line, 11-09: 31.5Closing line, 11-11: 31.5Closing line, 11-12: 31.5Closing line, 11-15: 30.5Closing line, 11-17: 30.5Closing line, 11-19: 31.5Closing line, 11-21: 31.5Closing line, 11-23: 31.5Closing line, 11-26: 31.5Closing line, 11-28: 31.5Closing line, 11-30: 31.5Closing line, 12-02: 30.5Closing line, 12-05: 31.5Closing line, 12-10: 30.5Closing line, 12-13: 31.5Closing line, 12-18: 30.5Closing line, 12-19: 31.5Closing line, 12-22: 32.5Closing line, 12-23: 31.5Closing line, 12-25: 32.5Closing line, 12-28: 30.5Closing line, 12-29: 30.5Closing line, 12-31: 31.5Closing line, 01-02: 30.5Closing line, 01-04: 30.5Closing line, 01-05: 30.5Closing line, 01-07: 31.5Closing line, 01-11: 30.5Closing line, 01-13: 30.5Closing line, 01-15: 30.5Closing line, 01-17: 31.5Closing line, 01-19: 32.5Closing line, 01-21: 32.5Closing line, 01-23: 33.5Closing line, 01-25: 32.5Closing line, 01-27: 32.5Closing line, 01-29: 32.5Closing line, 02-01: 31.5Closing line, 02-03: 32.5Closing line, 02-27: 28.5Closing line, 03-01: 30.5Closing line, 03-04: 30.5Closing line, 03-07: 31.5Closing line, 03-09: 32.5Closing line, 03-12: 30.5Closing line, 03-15: 32.5Closing line, 03-17: 31.5Closing line, 03-18: 27.5Closing line, 03-21: 28.5Closing line, 03-23: 29.5Closing line, 03-25: 29.5Closing line, 03-27: 29.5Closing line, 03-29: 30.5Closing line, 03-30: 30.5Closing line, 04-02: 31.5Closing line, 04-05: 29.5Closing line, 04-07: 28.5Closing line, 04-08: 29.5Points scoredPoints scored, 10-21: 35.0Points scored, 10-23: 55.0Points scored, 10-25: 30.0Points scored, 10-27: 23.0Points scored, 10-28: 31.0Points scored, 10-30: 31.0Points scored, 11-02: 30.0Points scored, 11-04: 30.0Points scored, 11-05: 35.0Points scored, 11-07: 30.0Points scored, 11-09: 35.0Points scored, 11-11: 28.0Points scored, 11-12: 30.0Points scored, 11-15: 33.0Points scored, 11-17: 23.0Points scored, 11-19: 33.0Points scored, 11-21: 31.0Points scored, 11-23: 37.0Points scored, 11-26: 40.0Points scored, 11-28: 37.0Points scored, 11-30: 26.0Points scored, 12-02: 38.0Points scored, 12-05: 33.0Points scored, 12-10: 28.0Points scored, 12-13: 29.0Points scored, 12-18: 32.0Points scored, 12-19: 35.0Points scored, 12-22: 31.0Points scored, 12-23: 33.0Points scored, 12-25: 22.0Points scored, 12-28: 27.0Points scored, 12-29: 39.0Points scored, 12-31: 30.0Points scored, 01-02: 30.0Points scored, 01-04: 25.0Points scored, 01-05: 21.0Points scored, 01-07: 46.0Points scored, 01-11: 29.0Points scored, 01-13: 34.0Points scored, 01-15: 20.0Points scored, 01-17: 39.0Points scored, 01-19: 30.0Points scored, 01-21: 40.0Points scored, 01-23: 47.0Points scored, 01-25: 24.0Points scored, 01-27: 29.0Points scored, 01-29: 30.0Points scored, 02-01: 34.0Points scored, 02-03: 20.0Points scored, 02-27: 36.0Points scored, 03-01: 30.0Points scored, 03-04: 26.0Points scored, 03-07: 27.0Points scored, 03-09: 35.0Points scored, 03-12: 35.0Points scored, 03-15: 20.0Points scored, 03-17: 40.0Points scored, 03-18: 20.0Points scored, 03-21: 40.0Points scored, 03-23: 22.0Points scored, 03-25: 33.0Points scored, 03-27: 25.0Points scored, 03-29: 30.0Points scored, 03-30: 47.0Points scored, 04-02: 28.0Points scored, 04-05: 20.0Points scored, 04-07: 25.0Points scored, 04-08: 20.0

68 graded games. The line is the median closing line across books. It stayed between 27.5 and 33.5; his points ranged from 20 to 55.

The line moves in a narrow band while the result swings far more. That gap is why a hit rate over a few dozen games says little on its own.

4. Over rate by month, with the count

Group the saved file by month and by whether the line moved between open and close. Always print the number of games next to a rate.

import pandas as pd

df = pd.read_csv("sga_points_props_2025_26.csv")
graded = df.dropna(subset=["result"]).copy()
graded["month"] = graded["game_date"].str[:7]
graded["over"] = graded["result"] == "over"

by_month = graded.groupby("month").agg(games=("over", "size"), overs=("over", "sum"))
by_month["over_rate"] = (by_month["overs"] / by_month["games"]).round(3)
print(by_month.to_string())

graded["direction"] = graded["moved"].apply(lambda m: "up" if m > 0 else "down" if m < 0 else "unchanged")
print(graded.groupby("direction").agg(games=("over", "size"), overs=("over", "sum")).to_string())

Output

         games  overs  over_rate
month
2025-10      6      2      0.333
2025-11     15      7      0.467
2025-12     12      6      0.500
2026-01     14      5      0.357
2026-02      3      2      0.667
2026-03     14      6      0.429
2026-04      4      0      0.000
           games  overs
direction
down          12      3
unchanged     41     16
up            15      9

Every month has 15 games or fewer, so a month's rate can swing by 20 points on two or three results. The line moved between open and close in 27 games (15 up, 12 down). These counts describe one player's season; they are too small to read as a pattern.

5. How one line moved before tip-off

get_prop_movement returns every capture we hold for one player, game and market, book by book. This is Jan 23, 2026, when the median line opened at 32.5 and closed at 33.5.

from dunkapi import Client

client = Client()
game_id, player_id = "401810496", "4278073"

movement = client.get_prop_movement(game_id, player_id, "player_points")
for book in movement["books"]:
    first, last = book["snapshots"][0], book["snapshots"][-1]
    print(len(book["snapshots"]), first["line"], "->", last["line"], last["minutes_before_scheduled_start"])

Output

6 32.5 -> 33.5 -5.6
6 32.5 -> 33.5 -5.6
4 32.5 -> 32.5 34.4
6 32.5 -> 33.5 -5.6
6 32.5 -> 32.5 -5.6
8 32.5 -> 33.5 -5.6
6 32.5 -> 33.5 -5.6

Seven books, 42 captures. Five books moved from 32.5 to 33.5 and two stayed at 32.5. A negative minutes_before_scheduled_start means the capture was taken after the scheduled start time (here 5.6 minutes after); filter on it if you want strictly pre-start prices. Each book's row also carries bookmaker and line_change.

6. The market's probability for the same prop

get_prop_probabilities turns each book's prices into one number per line: the average implied probability with the margin in, and the fair probability with the margin taken out. Books are only combined when they post the same line.

probs = client.get_prop_probabilities(game_id, market="player_points", player_id=player_id)
for line in probs["props"][0]["lines"]:
    print(line["line"], line["books_used"], line["over"]["fair_prob"], line["under"]["fair_prob"])

Output

33.5 5 0.485 0.515
32.5 2 0.515 0.485

Five books at 33.5 put the over at 48.5% with the margin removed; the two still at 32.5 put it at 51.5%. Both say the market saw the over as close to even. He scored 47 that night, one game that says nothing about whether those numbers were right.

7. Test the whole record with get_prop_backtest

Instead of pulling every row, get_prop_backtest grades every game we hold prices for that fits your filters and returns the hit rate with a 95% interval, the market's average fair probability, and each season on its own. Seasons are named by the year they end (2026 is 2025-26), and the count includes playoff games.

from dunkapi import Client

client = Client()
bt = client.get_prop_backtest("player_points", player_id="4278073", side="over")
print(bt["results"], bt["hits"], bt["hit_rate"], bt["hit_rate_interval_95"], bt["avg_fair_prob"])
for s in bt["by_season"]:
    print(s["season"], s["results"], s["hits"], s["hit_rate"], s["avg_fair_prob"])

Output

289 136 0.471 [0.414, 0.528] 0.499
2024 85 41 0.482 0.502
2025 100 50 0.5 0.499
2026 83 34 0.41 0.496
2027 21 11 0.524 0.501

How to read it:

  • Sample: 289 graded games since 2023-24, 136 overs, a 47.1% hit rate.
  • Interval: the 95% interval runs from 41.4% to 52.8%. The market's average fair probability, 49.9%, is inside it, so this record cannot be told apart from the market's own number.
  • By season: 48.2%, 50.0%, 41.0% and 52.4% (21 games so far this season). One low season pulls the total down; the others sit near 50%.

A past hit rate is not a forecast. If you try many filters, some will look unusual by chance alone, so check the interval and by_season every time.

Tools and credits

One full run: 76 credits.

What you can do with the data

You may store these rows, train models and backtest on them, and build products that show your users what you derive. You may not redistribute the rows, or the prices as a raw feed, as a dataset or API of its own. Prop lines and prices are market information, not predictions or picks.

Details: data timing and rights.

What to do next

Start with 500 free credits every month

No card. pip install dunkapi, REST or MCP.