NFL Passing Efficiency API: Computing EPA, CPOE, and Air Yards in Python
Compute passing EPA per dropback, aDOT, YAC, and a custom air-yards CPOE baseline in Python using OpenPigskin's nflverse play-by-play REST API.
Why raw passing yards mislead quarterback evaluations
Traditional box scores treat a 3-yard screen that turns into a 25-yard gain the same as a 25-yard laser into a tight window on 3rd-and-12, and they leave sacks completely out of passing efficiency. Play-by-play metrics fix that gap by pairing Expected Points Added (EPA) with air yards, yards after catch (YAC), down-and-distance context and sack outcomes.
Look at three real postseason games in the OpenPigskin nflverse archive. In Super Bowl LIX (game_nfl_2024_22_KC_PHI, Philadelphia 40–22 Kansas City on 2025-02-09), Patrick Mahomes threw for more raw yards (257 on 21/35 with 3 TDs) than Jalen Hurts (221 on 17/22 with 2 TDs), yet across all pass dropbacks including sacks Hurts generated +12.745 passing EPA (+0.531 EPA/dropback across 24 dropbacks, 8.68 aDOT, 4.82 avg YAC) while Mahomes finished at -7.594 (-0.185 EPA/dropback across 41 dropbacks with 6 sacks taken and 2 interceptions).
Super Bowl LX (game_nfl_2025_22_SEA_NE, Seattle 29–13 New England on 2026-02-08) tells a similar story: Drake Maye posted 295 yards (27/44, 2 TDs, 2 INTs, 6 sacks taken) at -0.320 EPA/dropback (-16.009 total passing EPA across 50 dropbacks, 10.70 aDOT), whereas Sam Darnold's lower-volume 202-yard game (19/38, 1 TD, 0 INTs, 1 sack) stayed near neutral at -0.025 EPA/dropback (-0.958 across 39 dropbacks, 9.53 aDOT). Meanwhile, in the NFC Championship shootout (game_nfl_2025_21_LA_SEA, Seattle 31–27 Los Angeles), both quarterbacks dominated: Darnold posted +0.403 EPA/dropback (25/36, 346 yds, 3 TDs, 8.22 aDOT, 5.84 avg YAC) and Matthew Stafford posted +0.359 EPA/dropback (22/34, 374 yds, 3 TDs, 12.65 aDOT, 5.64 avg YAC).
Pull filtered pass plays from /v1/games/{id}/plays with pagination
Every detailed game exposes GET /v1/games/{id}/plays (Developer plan and above). Passing ?play_type=pass isolates pass attempts and sacks immediately, returning 100 plays per page with meta.next_cursor and the full nflverse CC BY 4.0 attribution block.
Each pass snap includes down, yards_to_go, yardline_100, epa, wpa, air_yards, yards_after_catch, yards_gained, sack, interception, touchdown, passer_id, passer_name, receiver_id and receiver_name. Notice one important detail about the contract: OpenPigskin does not store a precomputed cpoe column on /plays. Instead, it exposes the exact raw inputs (air_yards, down, yards_to_go, yardline_100 and completion outcomes) so your Python pipeline can compute reproducible EPA, aDOT, YAC and an auditable Completion Percentage Over Expected (CPOE) model without hidden black-box weights.
curl "https://openpigskinapi.com/v1/games/game_nfl_2024_22_KC_PHI/plays?play_type=pass" \
-H "Authorization: Bearer op_live_YOUR_KEY"Compute EPA per dropback, aDOT, and YAC per completion in Python
In OpenPigskin's play ledger, non-sack completions carry a non-null yards_after_catch integer while incomplete passes and sacks have yards_after_catch: null, and sacks are flagged directly with sack: true. You can cross-check completion and attempt totals anytime against GET /v1/games/{id}/boxscore.
The Python script below pages cleanly through /v1/games/{id}/plays?play_type=pass using only the standard library and outputs EPA per dropback, sack rate, average depth of target (aDOT) and YAC per completion for every quarterback in a game.
import json
import os
import urllib.parse
import urllib.request
from collections import defaultdict
API_KEY = os.environ["OPENPIGSKIN_KEY"]
BASE = "https://openpigskinapi.com"
def fetch_pass_plays(game_id: str) -> list[dict]:
plays: list[dict] = []
cursor: str | None = None
while True:
params = {"play_type": "pass"}
if cursor:
params["cursor"] = cursor
qs = urllib.parse.urlencode(params)
req = urllib.request.Request(
f"{BASE}/v1/games/{game_id}/plays?{qs}",
headers={"Authorization": f"Bearer {API_KEY}"},
)
with urllib.request.urlopen(req) as resp:
payload = json.loads(resp.read().decode("utf-8"))
plays.extend(payload["data"])
cursor = payload["meta"].get("next_cursor")
if not cursor:
break
return plays
def summarize_passing(game_id: str) -> list[dict]:
by_qb = defaultdict(lambda: {
"name": "", "team": "", "dropbacks": 0, "attempts": 0,
"completions": 0, "sacks": 0, "epa": 0.0,
"air_yards": [], "yac": [],
})
for p in fetch_pass_plays(game_id):
pid = p.get("passer_id")
if not pid:
continue
row = by_qb[pid]
row["name"] = p["passer_name"] or pid
row["team"] = p["posteam"] or ""
row["dropbacks"] += 1
if p["epa"] is not None:
row["epa"] += p["epa"]
if p["sack"]:
row["sacks"] += 1
continue
row["attempts"] += 1
if p["air_yards"] is not None:
row["air_yards"].append(p["air_yards"])
if p["yards_after_catch"] is not None:
row["completions"] += 1
row["yac"].append(p["yards_after_catch"])
summary = []
for pid, r in by_qb.items():
adot = round(sum(r["air_yards"]) / len(r["air_yards"]), 2) if r["air_yards"] else None
avg_yac = round(sum(r["yac"]) / len(r["yac"]), 2) if r["yac"] else None
summary.append({
"passer_id": pid,
"passer": r["name"],
"team": r["team"],
"dropbacks": r["dropbacks"],
"cmp_att": f"{r['completions']}/{r['attempts']}",
"sacks": r["sacks"],
"epa_per_dropback": round(r["epa"] / r["dropbacks"], 3),
"adot": adot,
"avg_yac": avg_yac,
})
return sorted(summary, key=lambda x: -x["epa_per_dropback"])
print(json.dumps(summarize_passing("game_nfl_2025_21_LA_SEA"), indent=2))Derive a transparent air-yards CPOE model across a multi-game sample
Because completion probability drops sharply as air_yards increases and tightens on late-down passing situations, raw completion percentage unfairly rewards checkdown passers over vertical passers like Stafford (12.65 aDOT in the 2025 NFC Championship).
Using OpenPigskin's /v1/games?season=2025&game_type=REG list to pull a multi-game training sample of pass snaps, you can fit a clean logistic regression (or empirical air-yards depth-bin baseline) predicting P(complete | air_yards, down, yards_to_go, yardline_100) and compute each passer's CPOE as actual completion percentage minus expected completion percentage.
from collections import defaultdict
def air_yard_bucket(air_yards: int) -> str:
if air_yards <= 0:
return "behind_los"
if air_yards <= 9:
return "short_1_9"
if air_yards <= 19:
return "intermediate_10_19"
return "deep_20_plus"
def compute_empirical_cpoe(all_pass_plays: list[dict]) -> dict[str, dict]:
# Step 1: Learn league baseline completion rate per (air_yard_bucket, down)
bucket_totals = defaultdict(lambda: [0, 0]) # [completions, attempts]
valid = [
p for p in all_pass_plays
if not p["sack"] and p["air_yards"] is not None and p["down"] is not None and p["passer_id"]
]
for p in valid:
key = (air_yard_bucket(p["air_yards"]), p["down"])
bucket_totals[key][1] += 1
if p["yards_after_catch"] is not None:
bucket_totals[key][0] += 1
expected_rate = {k: c / a for k, (c, a) in bucket_totals.items() if a > 0}
# Step 2: Score each passer's Completion Percentage Over Expected (CPOE)
qb_scores = defaultdict(lambda: {"name": "", "att": 0, "cmp": 0, "x_cmp": 0.0})
for p in valid:
key = (air_yard_bucket(p["air_yards"]), p["down"])
row = qb_scores[p["passer_id"]]
row["name"] = p["passer_name"] or p["passer_id"]
row["att"] += 1
row["cmp"] += 1 if p["yards_after_catch"] is not None else 0
row["x_cmp"] += expected_rate[key]
return {
pid: {
"passer": r["name"],
"attempts": r["att"],
"comp_pct": round(100.0 * r["cmp"] / r["att"], 1),
"x_comp_pct": round(100.0 * r["x_cmp"] / r["att"], 1),
"cpoe": round(100.0 * (r["cmp"] - r["x_cmp"]) / r["att"], 2),
}
for pid, r in qb_scores.items()
if r["att"] >= 15
}Attribute target air yards to receivers and reconcile with /boxscore
The exact same pass-play array powers receiver air-yards share: group non-sack plays by receiver_id, sum air_yards per receiver, and divide by the team's total air_yards to quantify downfield opportunity alongside targets and receptions from GET /v1/games/{id}/boxscore.
When building seasonal passing leaderboards across 2024 or 2025, combine your per-game EPA/aDOT pipeline with GET /v1/seasons/{id}/leaders?category=passing_yards and /v1/games/{id} (which already exposes top-level team_epa) so you only paginate /plays on games where play-by-play is imported (has_play_by_play: true) and avoid unnecessary HTTP 404 feature_not_available responses on older pre-import matchups.