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

source_loader = LivePossessionFileLoader("/data")
pbp_loader = LivePossessionLoader("0021900001", source_loader)
print(pbp_loader.items[0].data)  # prints dict with the first event of the game
class pbpstats.data_loader.live.possessions.loader.LivePossessionLoader(game_id, source_loader)[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:
data_provider = 'live'
parent_object = 'Game'
resource = 'Possessions'
class pbpstats.data_loader.live.possessions.file.LivePossessionFileLoader(file_directory)[source]

Bases: object

A LivePossessionFileLoader object should be instantiated and passed into LivePossessionLoader when loading data from file

Parameters:
  • game_id (str) – NBA Stats Game Id
  • file_directory (str) – Directory in which data should be loaded from. The specific file location will be live_<game_id>.json in the /pbp subdirectory.
class pbpstats.data_loader.live.possessions.web.LivePossessionWebLoader(file_directory=None)[source]

Bases: object

A LivePossessionWebLoader object should be instantiated and passed into LivePossessionLoader when loading data directly from the NBA Stats API

Parameters:file_directory (str) – (optional, use it if you want to store the response data on disk) Directory in which data should be either stored. 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.