Overview
The platform aggregates data from three complementary sources, each providing unique statistical coverage:NBA.com Stats API
Official league tracking data and advanced metrics
Basketball Reference
Historical totals and per-possession statistics
pbpstats.com API
Play-by-play derived metrics and on/off data
NBA.com Stats API
Overview
The official NBA statistics API provides tracking data, shooting metrics, and advanced analytics captured by SportVU cameras and official scorekeepers. Base URL:https://stats.nba.com/stats/
Available Endpoints
Hustle Statistics
Hustle Statistics
Endpoint:
leaguehustlestatsplayerScript: hustle.py:10-93Data Includes:- Deflections and charges drawn
- Screen assists and points created
- Offensive and defensive loose balls recovered
- Box outs (offensive/defensive)
- Contested shots (2PT/3PT split)
Shooting by Defender Distance
Shooting by Defender Distance
Endpoint:
leaguedashplayerptshotScript: player_shooting.py:65-122Data Includes:- Field goal attempts and makes by defender proximity
- Four distance categories:
- Very Tight: 0-2 feet
- Tight: 2-4 feet
- Open: 4-6 feet
- Wide Open: 6+ feet
- 2PT/3PT shooting splits
- Frequency percentages
Dribble-Based Shooting
Dribble-Based Shooting
Endpoint:
leaguedashplayerptshot (DribbleRange parameter)Script: dribble.py:13-77Data Includes:- Shooting splits by dribbles before shot:
- 0 Dribbles (catch & shoot)
- 1 Dribble
- 2 Dribbles
- 3-6 Dribbles
- 7+ Dribbles
- Pull-up vs. catch & shoot classification
- Jump shot analysis by dribbles
Defensive Tracking
Defensive Tracking
Endpoint:
leaguedashptdefendScript: defense.py:166-200Data Includes:- Opponent field goal percentage when defending
- Defensive field goals made/attempted
- Frequency of defensive matchups
- Rim protection (shots < 6 feet)
- Normal vs. expected FG% differential
Speed & Distance
Speed & Distance
Endpoint:
leaguedashptstatsScript: hustle.py:16-17Data Includes:- Average speed (MPH)
- Distance covered (miles)
- Average seconds per touch
- Average dribbles per touch
- Points per touch
Authentication & Headers
Required headers for all requests:Response Format
All NBA.com API endpoints return JSON with a consistent structure:Rate Limiting
Recommended delay: 1-3 seconds between requestsThe NBA.com API does not publish official rate limits, but excessive requests may result in temporary IP blocks.
Basketball Reference
Overview
Basketball Reference provides comprehensive historical statistics via HTML tables. The platform uses web scraping with BeautifulSoup to extract data. Base URL:https://www.basketball-reference.com/
Available Pages
- Per-Possession Stats
- Season Totals
- Playoffs
URL Pattern:
https://www.basketball-reference.com/leagues/NBA_{year}_per_poss.htmlScript: make_index.py:181-298Data Includes:- Points, FGA, FTA per 100 possessions
- True Shooting percentage
- Player efficiency metrics
- Team identification
Data Extraction with data-stat Attributes
Basketball Reference usesdata-stat attributes for reliable cell identification:
data-stat values:
player- Player nameteam_id- Team abbreviationg- Games playedmp- Minutes playedfga_per_poss,fg_per_poss- Field goalsfg3a_per_poss,fg3_per_poss- Three-pointersfta_per_poss,ft_per_poss- Free throwspts_per_poss- Points per possession
Player ID Mapping
Basketball Reference IDs are mapped to NBA.com IDs:Rate Limiting
pbpstats.com API
Overview
The pbpstats.com API provides play-by-play derived statistics including on/off data, lineup stats, and possession-level metrics. Base URL:https://api.pbpstats.com/
Available Endpoints
Player Totals
Player Totals
Endpoint:
get-totals/nbaScript: passing.py:15-48Parameters:Season: Format “2024-25”SeasonType: “Regular Season” or “Playoffs”Type: “Player” or “Team”
- Offensive possessions
- True shooting percentage
- Points unassisted (2PT/3PT)
- Assist breakdowns
- Turnover details
On/Off Statistics
On/Off Statistics
Endpoint:
get-on-off/nba/statScript: defense.py:96-138Parameters:Season: Format “2024-25”SeasonType: “Regular Season”, “Playoffs”, or “All”TeamId: Team ID from pbpstatsStat: Specific stat to query (e.g., “AtRimAccuracyOpponent”)
AtRimAccuracyOpponent- Opponent FG% at rimAtRimFrequencyOpponent- Frequency of opponent rim attemptsFG2APctBlocked- 2PT block percentage
Team & Player Index
Team & Player Index
Endpoints:
get-teams/nbaget-all-players-for-league/nba
defense.py:38-48Purpose: Get team and player ID mappings for pbpstats APIExample:Response Format
The pbpstats API returns JSON with player/team data:Merging with NBA.com Data
The passing script demonstrates multi-source merging:Rate Limiting
Recommended delay: 3 seconds between requests, especially in team loopsThe pbpstats API is community-maintained and should be used respectfully.
Data Integration Strategy
The platform combines all three sources:Common Identifiers
| Source | ID Field | Example | Format |
|---|---|---|---|
| NBA.com | PLAYER_ID | 2544 | Integer |
| Basketball Reference | bref_id | jamesle01 | String |
| pbpstats | EntityId | 2544 | String (converts to int) |
index_master.csv file maintains mappings:
Best Practices
Always Use Headers
Include proper User-Agent and Referer headers for all API requests
Respect Rate Limits
Implement delays between requests (2-3 seconds recommended)
Cache Results
Save responses locally to avoid redundant requests
Error Handling
Implement try/except blocks for network issues and missing data
Next Steps
API Scripts Reference
Explore detailed documentation for each data collection script