Pull today's NBA props every morning in Python
A 50-line Python script that saves today's NBA player prop lines to a dated CSV every morning, with a GitHub Actions workflow and a cron line to run it.
Every script run against the live API on December 5, 2026. One full run: 102 credits.
Prop lines move from the morning to tip-off, and the morning line is gone by the evening. A script that saves one dated file a day turns that into a record you can look back on. This guide builds it for the NBA: a short Python script that finds the games starting in the next 24 hours, pulls every player's prop lines for each one, and writes them to data/nba_props_<date>.csv. Then it runs the script for you every morning, with a GitHub Actions schedule or a cron line.
The same script works for the WNBA and men's college basketball: pass league="wnba" or league="ncaam" to both calls.
One full run on a night with 10 games costs 102 credits: 2 for the schedule and 10 for each game's props, because get_player_props is priced per game, not per line. A game with no lines yet costs nothing. Add estimate_only=True to a get_player_props call to see its price without paying it. The 500 free credits a month cover about five of these days, and a daily habit runs to about 3,000 credits a month.
1. Install the client and set your key
The client has no required dependencies, and the script below uses only the standard library. It needs Python 3.9 or newer, and the client reads your key from DUNKAPI_API_KEY. Put the key in the environment, never in the script.
pip install dunkapi
export DUNKAPI_API_KEY=your_key_here2. Write the script that saves today's props
The script asks get_schedule for the next day, keeps the games that start in the next 24 hours, and calls get_player_props once per game. The window matters: each game's lines are captured from about 30 hours before the start, at 15:00 and 20:00 UTC, and once more in the last 75 minutes. A run at 16:30 UTC therefore sees the 15:00 capture for every game in the window, where a run at 9:00 UTC would find tonight's games with no lines. A call that returns nothing is not charged, and the script prints the note the API sends with it. Each day's window starts where the last one ended, so a game lands in one file, give or take the minutes a scheduled run can start late. snapshot_type is left at its default, which returns the latest line captured before the game starts.
import csv
import time
from datetime import datetime, timedelta, timezone
from pathlib import Path
from dunkapi import Client
client = Client() # reads DUNKAPI_API_KEY
now = datetime.now(timezone.utc)
today = now.strftime("%Y-%m-%d")
COLUMNS = ["pulled_on", "game_id", "game_date", "home", "away", "player_name", "player_id", "market", "bookmaker", "line", "over_odds", "under_odds", "captured_at", "scheduled_start", "minutes_before_scheduled_start"]
def next_24_hours(rows, start_key):
"""Rows that start after now and no later than 24 hours from now."""
keep = []
for row in rows:
if row.get(start_key):
start = datetime.fromisoformat(row[start_key].replace("Z", "+00:00"))
if now < start <= now + timedelta(days=1):
keep.append(row)
return keep
rows = []
games = next_24_hours(client.get_schedule(days=1)["games"], "starts_at")
print(len(games), "games start in the next 24 hours")
for game in games:
data = client.get_player_props(game_id=game["game_id"])
for prop in data["props"]:
rows.append({"pulled_on": today, "home": game["home"]["abbrev"], "away": game["away"]["abbrev"], **prop})
if not data["props"]:
print(game["game_id"], data.get("note", "no lines yet"))
time.sleep(1.1) # stay under 60 requests a minute
if rows:
Path("data").mkdir(exist_ok=True)
out = Path("data") / f"nba_props_{today}.csv"
with out.open("w", newline="") as f:
writer = csv.DictWriter(f, fieldnames=COLUMNS, extrasaction="ignore")
writer.writeheader()
writer.writerows(rows)
print(len(rows), "lines saved to", out)
else:
print("nothing to save today")
print("credits left:", client.last_credits_remaining)Output
2 games start in the next 24 hours
401909453 No prop lines for this game yet: it has not started, and lines are captured from about 30 hours before the start (15:00 and 20:00 UTC, and once more in the last 75 minutes). Call again closer to the game.
234 lines saved to data/nba_props_2026-12-05.csv
credits left: 10619Save it as pull_nba_props.py and run it once by hand. It writes data/nba_props_<date>.csv, one file per day, and prints the credits left on the key that ran it. A day with nothing to save writes no file.
3. What each column means
Every row is one player, one market and one sportsbook. The columns, in file order:
- `pulled_on`: the UTC date the script ran. It is the same on every row of a file, which lets you stack the daily files.
- `home`, `away`: the teams' abbreviations from the schedule row, such as
BOSandNYK. - `game_id`: our id for the game, the same one
get_schedulereturns. - `game_date`: the game's date.
- `player_name`: the player as the sportsbook lists him.
- `player_id`: our player id, where the sportsbook's name matched a player in that game. Empty where it did not, so do not join on it without checking for gaps.
- `market`: the stat the line is on, such as
player_points. The list for the sport is under the table. - `bookmaker`: the sportsbook's key, such as
draftkings. - `line`: the number the over/under is set at, such as 24.5. It is empty for yes or no markets such as an anytime scorer, where
over_oddsis the price of yes. - `over_odds`, `under_odds`: the sportsbook's price for each side, in American format (
-115,+105). The prices include the sportsbook's margin, so two sides priced-115are not a 50% chance each. Some books post only one side, and the other is empty. - `captured_at`: when we captured that line, in UTC.
- `scheduled_start`: the game's scheduled start, in UTC.
- `minutes_before_scheduled_start`: minutes from
captured_attoscheduled_start. Positive means captured before the scheduled start.
The markets are player_points, player_rebounds, player_assists, player_threes, player_points_rebounds_assists, player_points_rebounds, player_points_assists, player_rebounds_assists, player_blocks, player_steals, player_double_double and player_triple_double. For the two double markets, over_odds is the price of yes. Not every sportsbook posts every market, and a quiet night has fewer lines. The prices are what the market showed at captured_at. They are information about the market, not a forecast of the game.
4. Run it every morning with GitHub Actions
Put the script in a private repository, add your key under Settings, Secrets and variables, Actions, and add this workflow as .github/workflows/daily-nba-props.yml. GitHub reads cron times as UTC and can start a scheduled run a few minutes late. The last step commits the new CSV, so the repository becomes your archive. Keep it private: the terms let you store this data but not redistribute it.
name: Daily NBA props
on:
schedule:
- cron: "30 16 * * *" # 16:30 UTC every day
workflow_dispatch: # lets you run it by hand once to test
permissions:
contents: write
jobs:
pull:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install dunkapi
- run: python pull_nba_props.py
env:
DUNKAPI_API_KEY: ${{ secrets.DUNKAPI_API_KEY }}
- run: |
git config user.name "daily-pull"
git config user.email "daily-pull@users.noreply.github.com"
mkdir -p data
git add data/
git diff --cached --quiet || git commit -m "NBA props $(date -u +%F)"
git pushRun it once from the Actions tab with the manual trigger before you trust the schedule. A failed run, such as a bad key or no credits, shows as a failed workflow and GitHub emails you.
5. Or run it from cron on your own machine
If you would rather keep the files local, one crontab line does the same job. Cron uses the machine's clock, so set the hour to 16:30 UTC in your own zone (11:30 on US Eastern time in winter). The key goes in a file only you can read, so it is not written into the crontab. Open the crontab with crontab -e.
# one-time setup
echo 'export DUNKAPI_API_KEY=your_key_here' > ~/.dunkapi_env && chmod 600 ~/.dunkapi_env
# crontab line: 16:30 every day, appends to a log
30 16 * * * cd ~/daily-pull && . ~/.dunkapi_env && python3 pull_nba_props.py >> pull.log 2>&1A laptop that is asleep at 16:30 skips the run, and cron does not catch up. On a machine that is not always on, use the GitHub workflow above.
6. Check the first file
Run the script by hand once and read the file it wrote. This prints the line count, the number of players and sportsbooks, and the median line in each market.
import glob
import pandas as pd
latest = sorted(glob.glob("data/nba_props_*.csv"))[-1]
df = pd.read_csv(latest)
print(latest, len(df), "lines,", df["player_name"].nunique(), "players,", df["bookmaker"].nunique(), "sportsbooks")
print(df.groupby("market").agg(lines=("line", "size"), players=("player_name", "nunique"), median_line=("line", "median")).round(1).to_string())Output
data/nba_props_2026-12-05.csv 234 lines, 12 players, 5 sportsbooks
lines players median_line
market
player_assists 41 9 4.5
player_points 59 12 11.5
player_points_rebounds_assists 40 9 22.5
player_rebounds 55 12 4.5
player_threes 39 8 2.5One game, 234 lines from 5 sportsbooks and 12 players, pulled on Dec 5 2026.
After a few days, read the files together to see how a line moved from one morning to the next. Read them as a record of what the market showed, not as a forecast.
Tools and credits
- get_schedule: 1 call, 2 credits.
- get_player_props: 10 calls, 100 credits (a 10-game night; 10 credits a game before it starts).
One full run: 102 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. Prices and lines are market information, not predictions or advice.
Details: data timing and rights.
What to do next
Start with 500 free credits every month
No card. pip install dunkapi, REST or MCP.