Skip to content

Guides

Historical NFL odds as a CSV in Python

A 20-line Python script that writes every NFL regular-season game since 1999 with its closing spread, total and moneylines to one CSV file.

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

This tutorial writes one file: every NFL regular-season game from 1999 through 2025, with the final score and the consensus closing spread, total and moneylines on the same row. That is 6,967 games in 27 seasons.

The closing spread and total are on every game since 1999. Moneylines start in 2006 and are on every game from 2010. One full run makes 27 calls to get_games, one per season, for 135 credits; the per-book section at the end adds 10, so a full run is 145 credits. The free plan's monthly credits cover it.

1. Install the client and set your key

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

pip install "endzoneapi[pandas]" matplotlib
export ENDZONEAPI_API_KEY=your_key_here

2. Write the CSV

get_games returns a whole season in one call when limit is 500 (a regular season is at most 272 games). game_type="REG" leaves out the playoffs; drop it to keep them. The script keeps the columns a closing-line file needs and sorts by season and week.

import pandas as pd
from endzoneapi import Client, to_dataframe

client = Client()  # reads ENDZONEAPI_API_KEY

frames = []
for season in range(1999, 2026):
    games = client.get_games(season=season, game_type="REG", limit=500)
    frames.append(to_dataframe(games, key="games"))

df = pd.concat(frames, ignore_index=True)
cols = [
    "game_id", "season", "week", "gameday", "away_team", "home_team",
    "away_score", "home_score", "result", "total",
    "spread_line", "total_line", "away_moneyline", "home_moneyline",
]
df = df[cols].sort_values(["season", "week", "gameday", "game_id"])
df.to_csv("nfl_closing_lines.csv", index=False)

print(len(df), "games,", df["season"].nunique(), "seasons")
print(df.tail(3).to_string(index=False))
print("credits left:", client.last_credits_remaining)

Output

6967 games, 27 seasons
        game_id  season  week    gameday away_team home_team  away_score  home_score  result  total  spread_line  total_line away_moneyline home_moneyline
2025_18_NYJ_BUF    2025    18 2026-01-04       NYJ       BUF           8          35      27     43         12.5        39.5            550           -800
2025_18_TEN_JAX    2025    18 2026-01-04       TEN       JAX           7          41      34     48         12.5        46.5            525           -750
2025_18_WAS_PHI    2025    18 2026-01-04       WAS       PHI          24          17      -7     41          3.0        38.5            150           -180
credits left: 1682

The last line is the credit balance of the key that ran it; yours will differ. The CSV is about 490 KB.

3. What each column means

ColumnMeaning
game_idseason_week_away_home, e.g. 2025_18_NYJ_BUF
gamedayLocal date of the game
resultHome score minus away score
totalPoints scored by both teams
spread_lineClosing spread, positive when the home team is favored
total_lineClosing total points line
home_moneyline, away_moneylineClosing moneylines in American odds; empty before 2006 and on some games to 2009
spread_line uses the opposite sign of a sportsbook's home spread: 12.5 means the home team was a 12.5-point favorite (-12.5 on a book's board).

Because result and spread_line share a sign, the home team covered when result > spread_line, and the game pushed when they are equal.

4. Check the file

Count games and filled lines by season before you use the file. A short season, or a column that stops being filled, shows up here first.

import pandas as pd

df = pd.read_csv("nfl_closing_lines.csv")

by_season = df.groupby("season").agg(
    games=("game_id", "size"),
    spread=("spread_line", "count"),
    total=("total_line", "count"),
    moneyline=("home_moneyline", "count"),
    avg_total_line=("total_line", "mean"),
    avg_points=("total", "mean"),
)
print(by_season.round(1).loc[[1999, 2005, 2006, 2008, 2010, 2020, 2022, 2025]].to_string())

home_cover = (df["result"] > df["spread_line"]).sum()
spread_push = (df["result"] == df["spread_line"]).sum()
over = (df["total"] > df["total_line"]).sum()
total_push = (df["total"] == df["total_line"]).sum()
n = len(df)
print(f"{n} games: home covered {home_cover}, spread pushes {spread_push} ({spread_push / n:.1%})")
print(f"overs {over}, total pushes {total_push} ({total_push / n:.1%})")

Output

        games  spread  total  moneyline  avg_total_line  avg_points
season
1999      248     248    248          0            40.1        41.6
2005      256     256    256          0            41.1        41.2
2006      256     256    256        209            40.4        41.3
2008      256     256    256        185            42.4        44.1
2010      256     256    256        256            42.7        44.1
2020      256     256    256        256            48.1        49.6
2022      271     271    271        271            44.1        43.8
2025      272     272    272        272            44.9        46.0
6967 games: home covered 3319, spread pushes 189 (2.7%)
overs 3399, total pushes 99 (1.4%)

What the counts say:

  • 248 games a season through 2001 (31 teams), 256 from 2002, 272 from 2021 (the 17-game schedule). 2022 has 271 because one game was canceled.
  • The spread and total are filled on all 6,967 games. Moneylines are missing on 1,901: all 1,768 games from 1999 to 2005 and 133 from 2006 to 2009.
  • 189 games (2.7%) landed exactly on the spread and 99 (1.4%) on the total. Leave pushes out of any cover or over rate.

5. Chart the closing total by season

The closing total is the market's number for points in a game. Plotting its season average against what was actually scored shows how the line followed scoring.

import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv("nfl_closing_lines.csv")
by_season = df.groupby("season")[["total_line", "total"]].mean()
ax = by_season.plot(marker="o", figsize=(9, 4))
ax.set_ylabel("Points per game")
ax.legend(["Closing total", "Points scored"])
plt.tight_layout()
plt.savefig("nfl_totals_by_season.png", dpi=150)
Average closing total and points scored per game, NFL regular season
  • Closing total
  • Points scored
37.540.042.545.047.550.0SeasonPoints per game200120042007201020132016201920222025Closing totalClosing total, 1999: 40.1Closing total, 2000: 41.5Closing total, 2001: 39.8Closing total, 2002: 41.5Closing total, 2003: 41.0Closing total, 2004: 41.8Closing total, 2005: 41.1Closing total, 2006: 40.4Closing total, 2007: 41.4Closing total, 2008: 42.4Closing total, 2009: 42.7Closing total, 2010: 42.7Closing total, 2011: 43.6Closing total, 2012: 44.6Closing total, 2013: 45.3Closing total, 2014: 46.0Closing total, 2015: 45.1Closing total, 2016: 45.6Closing total, 2017: 44.1Closing total, 2018: 46.5Closing total, 2019: 45.1Closing total, 2020: 48.1Closing total, 2021: 46.5Closing total, 2022: 44.1Closing total, 2023: 42.9Closing total, 2024: 44.3Closing total, 2025: 44.9Points scoredPoints scored, 1999: 41.6Points scored, 2000: 41.3Points scored, 2001: 40.4Points scored, 2002: 43.3Points scored, 2003: 41.7Points scored, 2004: 43.0Points scored, 2005: 41.2Points scored, 2006: 41.3Points scored, 2007: 43.4Points scored, 2008: 44.1Points scored, 2009: 42.9Points scored, 2010: 44.1Points scored, 2011: 44.4Points scored, 2012: 45.5Points scored, 2013: 46.8Points scored, 2014: 45.2Points scored, 2015: 45.6Points scored, 2016: 45.6Points scored, 2017: 43.4Points scored, 2018: 46.7Points scored, 2019: 45.6Points scored, 2020: 49.6Points scored, 2021: 46.0Points scored, 2022: 43.8Points scored, 2023: 43.5Points scored, 2024: 45.8Points scored, 2025: 46.0

From the CSV above: 6,967 games, 1999 to 2025. 2020 is the high for both (48.1 and 49.6).

6. Add each book's line for one game

The consensus close is one number per game. get_odds with a game_id returns each book's line as well: closing lines from 2014, and opening, closing and latest lines from 2020. It costs 10 credits a game, so use it for the games you need rather than the whole file.

from endzoneapi import Client

client = Client()

odds = client.get_odds(game_id="2024_01_NYJ_SF", snapshot_type="closing")
print(odds["consensus_closing"])
for book in odds["books"]:
    c = book["closing"]
    print(c["spread_home"], c["spread_home_odds"], c["total"], c["ml_home"], c["ml_away"])

Output

{'spread_line': 3.5, 'total_line': 43, 'home_moneyline': -180, 'away_moneyline': 150}
-3.5 -105 43 -190 155
-3.5 -110 43 -195 170
-3.5 -115 43.5 -195 165
-3.5 -108 43 -192 160
-3.5 -110 43.5 -190 160
-3.5 -110 43.5 -184 154
-3.5 -110 43 -190 153
-3.5 -110 43 -193 172

Eight books closed this game. All had the home team at -3.5 (spread_line 3.5 in the CSV), and the total closed at 43 or 43.5. Per-book rows also carry bookmaker, captured_at and implied probabilities (ml_home_prob, ml_away_prob) with the book's margin in them.

Tools and credits

  • get_games: 27 calls, 135 credits (one call per season, 1999 to 2025).
  • get_odds: 1 call, 10 credits (one game, optional).

One full run: 145 credits.

What you can do with the data

You may store this file, train models and backtest on it, and build products that show your users what you derive from it. You may not redistribute the rows, or the odds as a raw feed, as a dataset or API of its own. Closing lines 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 endzoneapi, REST or MCP.