data.nba.com Data Loaders

data.nba.com data loaders are used to load data for a specific resource either from file stored on disk or via an API request to data.nba.com.

Boxscore

DataNbaBoxscoreLoader loads boxscore data for a game and creates DataNbaBoxscoreItem objects for each player and team

The following code will load boxscore data for game id “0021900001” from a file located in a subdirectory of the /data directory

from pbpstats.data_loader import DataNbaBoxscoreLoader

boxscore_loader = DataNbaBoxscoreLoader("0021900001", "file", "/data")
print(boxscore_loader.items[0].data) # prints dict with a player's boxscore data for game
class pbpstats.data_loader.data_nba.boxscore_loader.DataNbaBoxscoreLoader(game_id, source, file_directory=None)[source]

Bases: pbpstats.data_loader.data_nba.file_loader.DataNbaFileLoader, pbpstats.data_loader.data_nba.web_loader.DataNbaWebLoader

Loads data.nba.com source boxscore data for game. Team/Player data is stored in items attribute as DataNbaBoxscoreItem objects

Parameters
  • game_id (str) – NBA Stats Game Id

  • source (str) – Where should data be loaded from. Options are ‘web’ or ‘file’

  • file_directory (str) – (optional if source is ‘web’) Directory in which data should be either stored (if source is web) or loaded from (if source is file). The specific file location will be data_<game_id>.json in the /game_details subdirectory. If not provided response data will not be saved on disk.

property data

returns raw JSON response data

data_provider = 'data_nba'
parent_object = 'Game'
resource = 'Boxscore'

Enhanced PBP

DataNbaEnhancedPbpLoader loads pbp data for a game and creates EnhancedPbpItem objects for each event

Enhanced data for each event includes current players on floor, score, fouls to give and number of fouls committed by each player, plus additional data depending on event type

The following code will load pbp data for game id “0021900001” from a file located in a subdirectory of the /data directory

from pbpstats.data_loader import DataNbaEnhancedPbpLoader

pbp_loader = DataNbaEnhancedPbpLoader("0021900001", "file", "/data")
print(pbp_loader.items[0].data)  # prints dict with the first event of the game
class pbpstats.data_loader.data_nba.enhanced_pbp_loader.DataNbaEnhancedPbpLoader(game_id, source, file_directory=None)[source]

Bases: pbpstats.data_loader.data_nba.pbp_loader.DataNbaPbpLoader, pbpstats.data_loader.nba_enhanced_pbp_loader.NbaEnhancedPbpLoader

Loads data.nba.com source enhanced pbp data for game. Events are stored in items attribute as EnhancedPbpItem objects

Parameters
  • game_id (str) – NBA Stats Game Id

  • source (str) – Where should data be loaded from. Options are ‘web’ or ‘file’

  • file_directory (str) – (optional if source is ‘web’) Directory in which data should be either stored (if source is web) or loaded from (if source is file). The specific file location will be data_<game_id>.json in the /pbp subdirectory. If not provided response data will not be saved on disk.

Raises

InvalidNumberOfStartersException: If all 5 players that start the period for a team can’t be determined. You can add the correct period starters to overrides/missing_period_starters.json in your data directory to fix this.

data_provider = 'data_nba'
parent_object = 'Game'
resource = 'EnhancedPbp'

File Loader

class pbpstats.data_loader.data_nba.file_loader.DataNbaFileLoader[source]

Bases: pbpstats.data_loader.abs_data_loader.AbsDataLoader

Base class for loading data.nba.com files saved on disk.

All data.nba.com data loader classes should inherit from this class.

This class should not be instantiated directly.

PBP

DataNbaPbpLoader loads pbp data for a game and creates DataNbaPbpItem objects for each event

The following code will load pbp data for game id “0021900001” from a file located in a subdirectory of the /data directory

from pbpstats.data_loader import DataNbaPbpLoader

pbp_loader = DataNbaPbpLoader("0021900001", "file", "/data")
print(pbp_loader.items[0].data)  # prints dict with the first event of the game
class pbpstats.data_loader.data_nba.pbp_loader.DataNbaPbpLoader(game_id, source, file_directory=None)[source]

Bases: pbpstats.data_loader.data_nba.file_loader.DataNbaFileLoader, pbpstats.data_loader.data_nba.web_loader.DataNbaWebLoader

Loads data.nba.com source pbp data for game. Events are stored in items attribute as DataNbaPbpItem objects

Parameters
  • game_id (str) – NBA Stats Game Id

  • source (str) – Where should data be loaded from. Options are ‘web’ or ‘file’

  • file_directory (str) – (optional if source is ‘web’) Directory in which data should be either stored (if source is web) or loaded from (if source is file). The specific file location will be data_<game_id>.json in the /pbp subdirectory. If not provided response data will not be saved on disk.

property data

returns raw JSON response data

data_provider = 'data_nba'
parent_object = 'Game'
resource = 'Pbp'

Possessions

DataNbaPossessionLoader loads possession data for a game and creates Possession objects for each possession

The following code will load possession data for game id “0021900001” from a pbp file located in the /pbp subdirectory of the /data directory

from pbpstats.data_loader import DataNbaPossessionLoader

possession_loader = DataNbaPossessionLoader("0021900001", "file", "/data")
print(possession_loader.items[0].data)  # prints dict with the first possession of the game
class pbpstats.data_loader.data_nba.possessions_loader.DataNbaPossessionLoader(game_id, source, file_directory=None)[source]

Bases: pbpstats.data_loader.nba_possession_loader.NbaPossessionLoader

Loads data.nba.com source possession data for game. Possessions are stored in items attribute as Possession objects

Parameters
  • game_id (str) – NBA Stats Game Id

  • source (str) – Where should data be loaded from. Options are ‘web’ or ‘file’

  • file_directory (str) – (optional if source is ‘web’) Directory in which data should be either stored (if source is web) or loaded from (if source is file). The specific file location will be data_<game_id>.json in the /pbp subdirectory. If not provided response data will not be saved on disk.

data_provider = 'data_nba'
parent_object = 'Game'
resource = 'Possessions'

Schedule

DataNbaScheduleLoader loads schedule data for a season and creates DataNbaGameItem objects for each game

The following code will load schedule data for 2019-20 NBA Regular Season

from pbpstats.data_loader import DataNbaScheduleLoader

schedule_loader = DataNbaScheduleLoader("nba", "2019-20", "Regular Season", "web")
print(schedule_loader.items[0].data)  # prints dict with the first game of the season
class pbpstats.data_loader.data_nba.schedule_loader.DataNbaScheduleLoader(league, season, season_type, source, file_directory=None)[source]

Bases: pbpstats.data_loader.data_nba.file_loader.DataNbaFileLoader, pbpstats.data_loader.data_nba.web_loader.DataNbaWebLoader

Loads data.nba.com source schedule data for season. Games are stored in items attribute as DataNbaGameItem objects

Parameters
  • league (str) – Options are ‘nba’, ‘wnba’ or ‘gleague’

  • season (str) – Can be formatted as either 2019-20 or 2019.

  • season_type (str) – Options are ‘Regular Season’ or ‘Playoffs’ or ‘Play In’

  • source (str) – Where should data be loaded from. Options are ‘web’ or ‘file’

  • file_directory (str) – (optional if source is ‘web’) Directory in which data should be either stored (if source is web) or loaded from (if source is file). The specific file location will be data_<league>_<season_year>.json in the /schedule subdirectory. If not provided response data will not be saved on disk.

property data

returns raw JSON response data

data_provider = 'data_nba'
property league_id

Returns League Id for league.

00 for nba, 10 for wnba, 20 for g-league

parent_object = 'Season'
resource = 'Games'

Web Loader

class pbpstats.data_loader.data_nba.web_loader.DataNbaWebLoader[source]

Bases: pbpstats.data_loader.abs_data_loader.AbsDataLoader

Base class for loading data from data.nba.com API request.

All data.nba.com data loader classes should inherit from this class.

This class should not be instantiated directly.

property league

Returns League for game id.

First 2 in game id represent league - 00 for nba, 10 for wnba, 20 for g-league

property season

Returns year in which season starts for game id

4th and 5th characters in game id represent season year ex. for 2016-17 season 4th and 5th characters would be 16 and season should return 2016