live Data Loaders

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

Boxscore

LiveBoxscoreLoader loads boxscore data for a game and creates LiveBoxscoreItem 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 LiveBoxscoreLoader

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

Bases: pbpstats.data_loader.live.file_loader.LiveFileLoader, pbpstats.data_loader.live.web_loader.LiveWebLoader

Loads data.nba.com source boxscore data for game. Team/Player data is stored in items attribute as LiveBoxscoreItem 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 live_<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 = 'live'
parent_object = 'Game'
resource = 'Boxscore'

Enhanced PBP

LiveEnhancedPbpLoader 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 LiveEnhancedPbpLoader

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

Bases: pbpstats.data_loader.live.pbp_loader.LivePbpLoader, 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 live_<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 = 'live'
parent_object = 'Game'
resource = 'EnhancedPbp'

File Loader

class pbpstats.data_loader.live.file_loader.LiveFileLoader[source]

Bases: pbpstats.data_loader.abs_data_loader.AbsDataLoader

Base class for loading live data files saved on disk.

All live data data loader classes should inherit from this class.

This class should not be instantiated directly.

PBP

LivePbpLoader loads pbp data for a game and creates LivePbpItem 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 LivePbpLoader

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

Bases: pbpstats.data_loader.live.file_loader.LiveFileLoader, pbpstats.data_loader.live.web_loader.LiveWebLoader

Loads live data source pbp data for game. Events are stored in items attribute as LivePbpItem 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 live_<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 = 'live'
parent_object = 'Game'
resource = 'Pbp'

Possessions

LivePossessionLoader 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 LivePossessionLoader

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

Bases: pbpstats.data_loader.nba_possession_loader.NbaPossessionLoader

Loads live data 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 live_<game_id>.json in the /pbp subdirectory. If not provided response data will not be saved on disk.

data_provider = 'live'
parent_object = 'Game'
resource = 'Possessions'

Web Loader

class pbpstats.data_loader.live.web_loader.LiveWebLoader[source]

Bases: pbpstats.data_loader.abs_data_loader.AbsDataLoader

Base class for loading data from live data API request.

All live data 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