Skip to content

Guides

NFL data in Python: play-by-play, weekly stats and odds

Pull one team's season with the closing line on every row, one game's play-by-play with EPA and win probability, and a player's weekly stat lines, all in Python.

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

This tutorial gets NFL data into Python without scraping anything: a team's season with the closing line next to what its offense did, one game play by play, and a quarterback's weekly lines. The example is Kansas City's 2025 regular season. The same calls work for any team, game or player back to 1999.

One full run costs 47 credits: 5 each for the team's weekly stats and its games, 30 for three play-by-play calls, and 7 for the player lookup and his stat lines. 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 tables and matplotlib for the charts. The client reads your key from ENDZONEAPI_API_KEY.

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

2. Put a season's offense and its closing lines on the same rows

get_team_stats returns one team's season with a row for every game: passing and rushing EPA (expected points added) among about 150 columns. get_games returns the same games with the score and the consensus closing line. Both carry the game id, so they join directly. The script turns the line into Kansas City's point of view and works out the points the line implied for them: half the total plus half their spread.

import pandas as pd
from endzoneapi import Client, to_dataframe

client = Client()  # reads ENDZONEAPI_API_KEY

stats = client.get_team_stats(team="KC", season=2025)
weeks = to_dataframe(stats, key="weeks")[["gameId", "week", "opponentTeam", "passingEpa", "rushingEpa"]]
weeks = weeks.rename(columns={"gameId": "game_id"})
weeks["off_epa"] = weeks["passingEpa"] + weeks["rushingEpa"]

games = to_dataframe(client.get_games(team="KC", season=2025, game_type="REG", limit=30), key="games")
df = weeks.merge(games, on=["game_id", "week"])
home = df["home_team"] == "KC"
df["kc_spread"] = df["spread_line"].where(home, -df["spread_line"])
df["kc_margin"] = df["result"].where(home, -df["result"])
df["kc_points"] = df["home_score"].where(home, df["away_score"])
df["implied_total"] = df["total_line"] / 2 + df["kc_spread"] / 2
df.to_csv("kc_2025_weekly.csv", index=False)

cols = ["week", "opponentTeam", "off_epa", "kc_points", "implied_total", "kc_spread", "kc_margin"]
print(df[cols].round(1).head(6).to_string(index=False))
print(len(df), "games, credits left:", client.last_credits_remaining)

Output

 week opponentTeam  off_epa  kc_points  implied_total  kc_spread  kc_margin
    1          LAC     12.4         21           25.2        3.0         -6
    2          PHI     -7.7         17           22.5       -1.5         -3
    3          NYG      8.5         22           25.2        6.0         13
    4          BAL     15.7         37           23.0       -2.5         17
    5          JAX     11.9         28           24.5        3.5         -3
    6          DET     13.9         30           27.0        2.5         13
17 games, credits left: 1153

The last line is the credit balance of the key that ran it; yours will differ. The bye week has no row, so 17 games.

3. What the new columns mean

ColumnMeaning
off_epaPassing EPA plus rushing EPA in the game: points the offense added above what its field position and down and distance would predict
kc_spreadClosing spread from Kansas City's side, positive when they were favored
kc_marginKansas City's score minus the opponent's
implied_totalPoints the closing line implied for Kansas City: total_line / 2 + kc_spread / 2
spread_line in the API is positive when the home team is favored. The script flips it for away games.

4. See how the line and the offense lined up

Two numbers per game, the offense's EPA and the points the line implied, against what Kansas City scored.

import pandas as pd

df = pd.read_csv("kc_2025_weekly.csv")
df["vs_implied"] = df["kc_points"] - df["implied_total"]

print(df[["off_epa", "kc_points", "implied_total"]].corr().round(2).to_string())
print("average: EPA", df["off_epa"].mean().round(1), "| points", df["kc_points"].mean().round(1), "| implied", df["implied_total"].mean().round(1))
print("games above the implied total:", int((df["vs_implied"] > 0).sum()), "of", len(df))
extremes = df.sort_values("off_epa")[["week", "opponentTeam", "off_epa", "kc_points", "implied_total"]].round(1)
print(extremes.iloc[[0, -1]].to_string(index=False))

Output

               off_epa  kc_points  implied_total
off_epa           1.00       0.89           0.64
kc_points         0.89       1.00           0.60
implied_total     0.64       0.60           1.00
average: EPA 2.0 | points 21.3 | implied 24.3
games above the implied total: 5 of 17
 week opponentTeam  off_epa  kc_points  implied_total
   18           LV    -29.0         12           20.0
    7           LV     16.6         31           29.0

What the numbers say:

  • Game EPA tracks points closely (0.89 over 17 games). It tracks the points the line implied less closely (0.64): the line is set before the game, EPA is what happened in it.
  • Kansas City averaged 21.3 points against 24.3 implied and finished above the implied total in 5 of 17 games. That is one team over one season, not a rule.
  • The best offensive game by EPA was week 7 at 16.6 (31 points). The worst was week 18 at -29.0 (12 points), against the same opponent.

5. Chart points scored against the closing line's implied points

import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv("kc_2025_weekly.csv")
ax = df.plot(x="week", y=["kc_points", "implied_total"], marker="o", figsize=(9, 4))
ax.set_ylabel("Points")
ax.legend(["Points scored", "Closing line implied"])
plt.tight_layout()
plt.savefig("kc_points_vs_implied.png", dpi=150)
Kansas City points scored and points implied by the closing line, 2025 regular season
  • Points scored
  • Closing line implied
0.010.020.030.040.0WeekPoints1357912141618Points scored, 1: 21.0Points scored, 2: 17.0Points scored, 3: 22.0Points scored, 4: 37.0Points scored, 5: 28.0Points scored, 6: 30.0Points scored, 7: 31.0Points scored, 8: 28.0Points scored, 9: 21.0Points scored, 11: 19.0Points scored, 12: 23.0Points scored, 13: 28.0Points scored, 14: 10.0Points scored, 15: 13.0Points scored, 16: 9.0Points scored, 17: 13.0Points scored, 18: 12.0Closing line implied, 1: 25.2Closing line implied, 2: 22.5Closing line implied, 3: 25.2Closing line implied, 4: 23.0Closing line implied, 5: 24.5Closing line implied, 6: 27.0Closing line implied, 7: 29.0Closing line implied, 8: 29.5Closing line implied, 9: 28.0Closing line implied, 11: 24.0Closing line implied, 12: 27.0Closing line implied, 13: 28.5Closing line implied, 14: 23.0Closing line implied, 15: 23.5Closing line implied, 16: 20.5Closing line implied, 17: 12.0Closing line implied, 18: 20.0

17 games, from the CSV above. The implied points are half the closing total plus half Kansas City's closing spread.

6. Play-by-play for one game

get_plays takes a game_id and returns every play with EPA, win probability, the players involved and a summary of the whole query. Game ids are season, week, away team and home team. This is Kansas City's week 4 home game against Baltimore. The script keeps the passes and runs and groups them by team.

import pandas as pd
from endzoneapi import Client, to_dataframe

client = Client()

game_id = "2025_04_BAL_KC"
pbp = client.get_plays(game_id=game_id, limit=500)
print(pbp["summary"], pbp["count"])

plays = to_dataframe(pbp, key="plays")
plays.to_csv("bal_kc_plays.csv", index=False)

scrimmage = plays[plays["play_type"].isin(["pass", "run"])]
by_type = scrimmage.groupby(["posteam", "play_type"]).agg(
    plays=("epa", "size"), epa_per_play=("epa", "mean"), success=("success", "mean")
)
print(by_type.round(2).to_string())

swing = scrimmage.reindex(scrimmage["wpa"].abs().sort_values(ascending=False).index).head(3)
print(swing[["qtr", "time", "posteam", "play_type", "yards_gained", "epa", "wpa"]].round(2).to_string(index=False))
print("credits left:", client.last_credits_remaining)

Output

{'scope': 'every play the filter matches', 'plays': 168, 'epa_total': 6.14, 'epa_per_play': 0.037, 'success_rate': 0.464} 168
                   plays  epa_per_play  success
posteam play_type                              
BAL     pass          36         -0.25     0.50
        run           17          0.39     0.53
KC      pass          38          0.33     0.58
        run           30         -0.02     0.30
 qtr  time posteam play_type  yards_gained   epa   wpa
   1 01:50     BAL      pass           0.0 -3.47 -0.11
   1 02:17     BAL      pass          17.0  2.12  0.09
   1 13:00     BAL      pass          21.0  1.13  0.08
credits left: 1143

The game had 168 plays in all. Kansas City passed 38 times at 0.33 EPA per play and ran 30 times at -0.02; Baltimore passed 36 times at -0.25. The largest single swing was a Baltimore interception late in the first quarter (-3.47 EPA, -0.11 win probability). wpa is the change in the offense's win probability on the play.

7. Chart win probability through the game

Each play carries wp, the win probability of the team with the ball before the snap. Flip it for the other team's plays to get one team's line, then take the first play of each drive.

import pandas as pd

plays = pd.read_csv("bal_kc_plays.csv")
plays = plays[plays["posteam"].notna()]
plays["kc_wp"] = plays["wp"].where(plays["posteam"] == "KC", 1 - plays["wp"])
starts = plays.groupby("drive").first()[["qtr", "time", "kc_wp"]]
print(len(starts), "drives")
print(starts.round(2).head(5).to_string())
print("lowest KC win probability at a drive start:", starts["kc_wp"].min().round(3), "| highest:", starts["kc_wp"].max().round(3))

Output

20 drives
       qtr   time  kc_wp
drive                   
1        1  15:00   0.57
2        1  09:35   0.39
3        1  05:40   0.42
4        1  01:44   0.44
5        2  10:00   0.49
lowest KC win probability at a drive start: 0.395 | highest: 1.0
Kansas City win probability at the start of each drive, week 4 vs Baltimore
0.0%20.0%40.0%60.0%80.0%100.0%DriveWin probability25811141720Kansas City win probability, 1: 56.6%Kansas City win probability, 2: 39.5%Kansas City win probability, 3: 42.2%Kansas City win probability, 4: 44.3%Kansas City win probability, 5: 48.7%Kansas City win probability, 6: 61.9%Kansas City win probability, 7: 72.9%Kansas City win probability, 8: 81.8%Kansas City win probability, 9: 89.2%Kansas City win probability, 10: 94.5%Kansas City win probability, 11: 88.9%Kansas City win probability, 12: 85.6%Kansas City win probability, 13: 91.9%Kansas City win probability, 14: 93.5%Kansas City win probability, 15: 95.6%Kansas City win probability, 16: 98.8%Kansas City win probability, 17: 99.7%Kansas City win probability, 18: 100.0%Kansas City win probability, 19: 100.0%Kansas City win probability, 20: 99.9%

20 drives. Kansas City won 37-20.

Kansas City started the game at 57%, was down to 39.5% by the start of the second drive, and stayed above 85% from drive 9 on.

8. EPA per play for a whole season in one call

get_plays summarizes every play your filter matches, not only the rows it returns. With limit=1 you pay for one call and read the summary: here, Kansas City's passing and rushing plays for all of 2025.

from endzoneapi import Client

client = Client()

for play_type in ["pass", "run"]:
    out = client.get_plays(season=2025, posteam="KC", play_type=play_type, limit=1)
    s = out["summary"]
    print(play_type, s["plays"], "plays,", s["epa_per_play"], "EPA per play,", s["success_rate"], "success rate")
print("credits left:", client.last_credits_remaining)

Output

pass 631 plays, 0.032 EPA per play, 0.445 success rate
run 417 plays, 0.04 EPA per play, 0.47 success rate
credits left: 1123

Over the season Kansas City's passes and runs were close to equal in value per play (0.032 and 0.040) across 631 passing and 417 rushing plays. Drop posteam and add week to summarize a league week, or use defteam for what a defense allowed.

9. A player's weekly stat lines

search_players finds the player id, and get_player_stats returns season totals and one row per game.

from endzoneapi import Client, to_dataframe

client = Client()

player = client.search_players("Mahomes", limit=1)["players"][0]
season = client.get_player_stats(player["player_id"], season=2025)
weekly = to_dataframe(season, key="weeks")
cols = ["week", "opponentTeam", "completions", "attempts", "passingYards", "passingTds", "passingEpa"]
print(player["name"], player["player_id"])
print(weekly[cols].round(1).head(4).to_string(index=False))
totals = season["season_totals"]
print(totals["passing_yards"], "yards,", totals["passing_tds"], "TD,", round(totals["passing_epa"], 1), "EPA in", totals["games"], "games")
print("credits left:", client.last_credits_remaining)

Output

Patrick Mahomes 00-0033873
 week opponentTeam  completions  attempts  passingYards  passingTds  passingEpa
    1          LAC           24        39           258           1         3.4
    2          PHI           16        29           187           1        -7.2
    3          NYG           22        37           224           1         8.2
    4          BAL           25        37           270           4        16.2
3587 yards, 22 TD, 68.2 EPA in 14 games
credits left: 1116

Mahomes played 14 of Kansas City's 17 games in 2025. The week 4 row is the Baltimore game from the play-by-play step: four touchdown passes and 16.2 passing EPA.

Tools and credits

One full run: 47 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 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.