Starter project
NFL player props pipeline with Python and Polars
This starter pulls NFL player prop history from EndzoneAPI into a Polars DataFrame and reports, for each market and season, how often the actual stat finished above the closing line. Two small files, about 220 credits, and a parquet file you can keep exploring. It describes history and gives no picks.
What you will build
A two-file pipeline. endzone.py is a thin API client. pipeline.py does the work in three stages: it asks the leaderboard for the top few players at each position, pulls each player's prop history for the matching market, and then groups the rows by market and season. The output is a small table with one row per market and season showing games graded, the share that finished over the line, the average line and the average actual result. The raw rows are also saved to props.parquet, so you can reopen them in any notebook without calling the API again.
Sample output from a real run (16 players, 1,183 graded and ungraded prop rows):
market season games overs over_rate avg_line avg_actual
player_pass_yds 2023 54 34 0.63 256.4 271.5
player_pass_yds 2024 73 39 0.534 242.0 247.0
player_pass_yds 2025 94 61 0.649 243.8 262.0
player_pass_yds 2026 53 27 0.509 251.1 250.5
player_reception_yds 2025 88 53 0.602 81.2 93.1
player_receptions 2025 87 51 0.586 6.7 7.2
player_rush_yds 2024 85 53 0.624 70.5 85.2
player_rush_yds 2026 49 24 0.49 79.7 85.2The full table has sixteen rows, four markets across four seasons. Read it as a description of these particular players: the leaders in each stat last season mostly finished above their lines, which is what you would expect from players selected because they produced. That selection effect is the main caveat on this page, and the limits section returns to it.
Prerequisites
- Python 3.9 or newer (the run below used 3.9.6).
- An EndzoneAPI key. The run below cost about 220 credits: 4 leaderboard calls at 5 credits and 20 history calls at 10 credits.
- Familiarity with DataFrames. Polars syntax is close enough to pandas that the code reads without a tutorial.
Keep the key in the ENDZONEAPI_KEY environment variable, not in code.
The project
nfl-props/
requirements.txt
endzone.py API client
pipeline.py pull, save to parquet, group by market and seasonrequirements.txt
polars>=1.0
requests>=2.31endzone.py
"""Tiny EndzoneAPI client. Reads the key from the ENDZONEAPI_KEY environment variable."""
import os
import requests
BASE = os.environ.get("ENDZONEAPI_BASE", "https://mcp.endzoneapi.com")
def call(tool: str, **params):
key = os.environ["ENDZONEAPI_KEY"]
resp = requests.post(
f"{BASE}/v1/{tool}",
headers={"x-api-key": key, "Content-Type": "application/json"},
json=params,
timeout=60,
)
resp.raise_for_status()
body = resp.json()
# Responses arrive wrapped as {"data": {...}}; unwrap if so.
return body.get("data", body)pipeline.py
"""Pull prop history for a few leaders per market and compute over rates by market and season."""
import polars as pl
from endzone import call
SEASON = 2025 # leaders are picked from this regular season
PER_MARKET = 5 # players per market (each history call costs 10 credits)
# market -> (leaderboard stat, position)
MARKETS = {
"player_pass_yds": ("passing_yards", "QB"),
"player_rush_yds": ("rushing_yards", "RB"),
"player_reception_yds": ("receiving_yards", "WR"),
"player_receptions": ("receptions", "WR"),
}
def season_of(date_str: str) -> int:
"""NFL season = year the regular season starts. Jan and Feb games belong to the prior year."""
y, m = int(date_str[:4]), int(date_str[5:7])
return y - 1 if m <= 2 else y
def pull() -> pl.DataFrame:
rows = []
for market, (stat, position) in MARKETS.items():
leaders = call("get_player_leaders", stat=stat, season=SEASON,
position=position, limit=PER_MARKET)["leaders"]
for p in leaders:
hist = call("get_prop_history", player_id=p["player_id"],
market=market, limit=200)
for g in hist["games"]:
rows.append({
"market": market,
"player": p["name"],
"game_date": g["game_date"],
"line": g["line"],
"actual": g["actual"],
"result": g["result"],
})
return pl.DataFrame(rows)
def hit_rates(df: pl.DataFrame) -> pl.DataFrame:
graded = df.filter(pl.col("result").is_in(["over", "under"]))
return (
graded.with_columns(
pl.col("game_date").map_elements(season_of, return_dtype=pl.Int64).alias("season")
)
.group_by(["market", "season"])
.agg(
pl.len().alias("games"),
(pl.col("result") == "over").sum().alias("overs"),
(pl.col("result") == "over").mean().round(3).alias("over_rate"),
pl.col("line").mean().round(1).alias("avg_line"),
pl.col("actual").mean().round(1).alias("avg_actual"),
)
.sort(["market", "season"])
)
if __name__ == "__main__":
df = pull()
df.write_parquet("props.parquet")
pl.Config.set_tbl_rows(40)
print(f"{df.height} prop rows, {df['player'].n_unique()} players")
print(hit_rates(df))How to run it
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
export ENDZONEAPI_KEY="your-key-here"
python pipeline.pyTo reopen the saved rows later without spending credits:
import polars as pl
df = pl.read_parquet("props.parquet")
df.filter(pl.col("market") == "player_pass_yds").head()How it works
Choosing players. The pipeline needs player ids before it can ask for history. get_player_leaders ranks players on any weekly stat and returns their GSIS ids, so the MARKETS dictionary pairs each prop market with the stat and position to rank on. Passing yards props go with quarterbacks, receiving yards and receptions with wide receivers, rushing yards with running backs. Change the dictionary to add tight ends, change PER_MARKET to widen the sample, or replace the leaderboard step with your own list of ids.
Pulling history. get_prop_history returns one row per game for a player and a market: the closing line (the median across books), the opening line, the actual stat, a result label and the margin. History starts in May 2023, so the first season in the table is the 2023 season. The limit is set to 200, the maximum, which is more than any player will have, so one call covers a whole career in the data.
Seasons. Rows carry a game date, not a season, and NFL seasons cross the new year. The helper season_of assigns January and February games to the season that started the previous year, which keeps playoff games with the right season. This is the sort of detail that silently skews a table if you group on calendar year instead.
Over rate. hit_rates keeps only rows the API graded as over or under, which drops pushes (the stat landed exactly on the line) and games with no result. It then groups by market and season and computes the count, the number of overs, the mean of the over flag, the average line and the average actual. The gap between average line and average actual is a useful second view: a market where the actual average sits well above the line is one where the median closing line ran low for these players.
Why Polars. The whole pull is about a thousand rows, so speed is not the reason. Polars is a good fit because the grouping expression reads top to bottom, because write_parquet gives you a typed file with no extra code, and because the same code keeps working if you widen the pull to hundreds of players.
Ways to extend it
- Add the situation columns. Join game-level data such as home or away, opponent, week or weather and group by those as well. Each new column splits the sample, so watch the games count in every cell.
- Add intervals. Compute a Wilson interval for each over rate with a few lines of Polars and Python. A rate of 0.60 on 50 games has an interval of roughly 0.46 to 0.72, which changes how you read the table.
- Compare with the server-side result. Run
get_prop_backtestfor one slice, such as quarterback passing yards, and check that its rate and sample size agree with your own table. It also reports an interval and a per-season breakdown. - Remove the selection effect. Instead of last season's leaders, rank players by a preseason measure such as prior-season snap share or depth chart position, so the sample is chosen before the results exist.
Limits and when not to use this
- Selection bias. The players here are last season's leaders in each stat. A group chosen for strong results will look better than the league average against its lines. Do not read these rates as the market's overall accuracy.
- Small samples. Cells hold 49 to 94 games. Rates move several points with a handful of results.
- Closing lines only. The line in each row is the median closing line across books. It is not a price anyone could have taken at a given time, and the file says nothing about how lines moved before kickoff. For that, use
get_prop_movement. - History, not forecasts. An over rate describes games already played. Nothing here estimates a future outcome, and the project does not compute stakes, payouts or returns.
- Data rights. You may store the data and use it for analysis and for products that show your users what you derive. You may not redistribute it as a raw feed or dataset. See the EndzoneAPI documentation for the full terms.
- Not for live use. The history is pre-game data. This is an analysis pipeline, not a feed for a game-day display.
FAQ
What does over rate mean here? It is the share of graded games where the player's actual total finished above the median closing line across books. Pushes and ungraded games are left out. It describes what happened, not what will happen.
Why not use the server-side backtest endpoint? The API has get_prop_backtest, which answers filtered questions in one 25 credit call. Pulling rows into Polars costs more but lets you slice by anything you can compute, such as opponent, week or line size.
Is a rate near 55 percent meaningful? Not by itself. With 50 to 90 games per cell, a few points either side of 50 is within normal noise, and these players were chosen because they produced. Always report the sample size next to the rate.
Live from the API
Free to embed on your own site, with no key needed. Get the embed code.
Get a free key Or download whole seasons as Parquet
Checked against the live API on 2026-12-06. Questions: hello@sportsdatahq.com.