How do I build an NBA shot chart by zone in Python?
A player's shot profile by zone, with attempts, makes and expected points per shot, for one season. Set include_shots to true to get every shot's x and y as well.
Code verified October 10, 2026. One call to get_shot_chart, 10 credits.
The call
player_id comes from search_players. Season 2026 is 2025-26.
import requests
import pandas as pd
API_KEY = "YOUR_API_KEY"
resp = requests.post(
"https://mcp.dunkapi.com/v1/get_shot_chart",
headers={"x-api-key": API_KEY},
json={
"player_id": "3975",
"season": 2026,
},
timeout=60,
)
resp.raise_for_status()
data = resp.json()["data"]
zones = pd.DataFrame(data["zones"])
zones["over_expected"] = zones["points_per_shot"] - zones["expected_points_per_shot"]
print(zones[["zone", "attempts", "pct", "points_per_shot", "expected_points_per_shot", "over_expected"]].round(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.
What comes back
The data object of the response, trimmed to the first rows. Every field is real output from the run above.
{
"season": 2026,
"zones": [
{
"zone": "restricted_area",
"attempts": 109,
"made": 76,
"pct": 0.697,
"points_per_shot": 1.394,
"expected_points_per_shot": 1.11
},
{
"zone": "paint",
"attempts": 115,
"made": 61,
"pct": 0.53,
"points_per_shot": 1.061,
"expected_points_per_shot": 0.775
},
"...4 more"
],
"field_goal_attempts": 803,
"share": {
"restricted_area": 0.136,
"paint": 0.143,
"midrange": 0.113,
"corner_3": 0.041,
"above_break_3": 0.567
}
}What to do next
- get_plays (10 credits). Filter plays by zone, period or clutch time to see which shots made up a zone.
- search_players (1 credit). Look up the player_id for anyone else.
More guides
Start with 500 free credits
No card. REST or MCP.