How do I backtest NFL closing lines in Python?
Every regular-season game with its score and the closing spread, total and moneylines on the same row, so a cover or over rate is one line of pandas.
Code verified November 18, 2026. One call to get_games, 5 credits.
The call
result is home score minus away score. spread_line is positive when the home team was favored.
import requests
import pandas as pd
API_KEY = "YOUR_API_KEY"
resp = requests.post(
"https://mcp.endzoneapi.com/v1/get_games",
headers={"x-api-key": API_KEY},
json={
"season": 2025,
"game_type": "REG",
"limit": 300,
},
timeout=60,
)
resp.raise_for_status()
data = resp.json()["data"]
games = pd.DataFrame(data["games"])
games = games[games["status"] == "FINAL"].copy()
games["home_cover"] = games["result"] > games["spread_line"]
games["push"] = games["result"] == games["spread_line"]
games["over"] = games["total"] > games["total_line"]
print(len(games), "games")
print("home covered:", round(games["home_cover"].mean(), 3))
print("over:", round(games["over"].mean(), 3))
favorite_home = games["spread_line"] > 0
print("home favorites covered:", round(games.loc[favorite_home, "home_cover"].mean(), 3))
Replace YOUR_API_KEY with a key from your dashboard. Python needs requests and pandas (pip install requests pandas). JavaScript runs on Node 18 or newer, or in the browser.
Or use the official client: pip install endzoneapi
What comes back
The data object of the response, trimmed to the first rows. Every field is real output from the run above.
{
"games": [
{
"game_id": "2025_18_BAL_PIT",
"week": 18,
"away_team": "BAL",
"home_team": "PIT",
"away_score": 24,
"home_score": 26,
"result": 2,
"total": 50,
"spread_line": -4.5,
"total_line": 41.5,
"away_moneyline": -225,
"home_moneyline": 185
},
{
"game_id": "2025_18_NYJ_BUF",
"week": 18,
"away_team": "NYJ",
"home_team": "BUF",
"away_score": 8,
"home_score": 35,
"result": 27,
"total": 43,
"spread_line": 12.5,
"total_line": 39.5,
"away_moneyline": 550,
"home_moneyline": -800
},
"...270 more"
],
"count": 272
}What to do next
- get_odds (10 credits). Each sportsbook's opening and closing line for one game, instead of the single closing line on the game row.
- get_alt_lines (10 credits). The full ladder of alternate spreads and totals (2023 on, this season included), if your rule needs a price at another number.
The data this uses
Every row above comes from NFL historical odds and closing lines. Closing spread and total for every NFL game since 1999, moneyline since 2010, a whole season in one call. REST or MCP, 500 free credits every month.
More guides
The same guide for other sports
- PuckAPI: How do I get NHL opening and closing odds by sportsbook in Python?
- FighterAPI: How do I compare UFC closing odds with fight results in Python?
- StrikerAPI: How do I get Premier League odds from every sportsbook with the results?
- DunkAPI: How do I backtest NBA closing lines in Python?
- AcesAPI: How do I compare ATP closing odds with the result and Elo in Python?
- BirdieAPI: How do I turn golf major winner odds into probabilities in Python?
- FastballAPI: How do I backtest MLB closing moneylines and run totals in Python?
- YorkerAPI: How do I get historical cricket odds in Python?
The latest lines from every book are on the odds board. Rather ask Claude? 16 free Claude skills call these endpoints for you.
Start with 500 free credits every month
No card. REST or MCP.