Possessions

StatsNbaPossessionLoader 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 StatsNbaPossessionFileLoader, StatsNbaPossessionLoader

source_loader = StatsNbaPossessionFileLoader("/data")
pbp_loader = StatsNbaPossessionLoader("0021900001", source_loader)
print(pbp_loader.items[0].data)  # prints dict with the first event of the game
class pbpstats.data_loader.stats_nba.possessions.loader.StatsNbaPossessionLoader(game_id, source_loader)[source]

Bases: pbpstats.data_loader.nba_possession_loader.NbaPossessionLoader

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

Parameters:
Raises:

TeamHasBackToBackPossessionsException: If team has the ball on back-to-back possessions.

data_provider = 'stats_nba'
league

Returns League for game id.

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

parent_object = 'Game'
resource = 'Possessions'
exception pbpstats.data_loader.stats_nba.possessions.loader.TeamHasBackToBackPossessionsException[source]

Bases: Exception

Class for exception when a team is credited with back-to-back possessions.

You can manually edit the event order in the pbp file stored on disk or add an event to the overrides file in your data directory to fix this.

class pbpstats.data_loader.stats_nba.possessions.file.StatsNbaPossessionFileLoader(file_directory)[source]

Bases: object

A StatsNbaPossessionFileLoader object should be instantiated and passed into StatsNbaPossessionLoader when loading data from file

Parameters:file_directory (str) – Directory in which data should be loaded from. The specific file location will be stats_<game_id>.json in the /pbp subdirectory.
class pbpstats.data_loader.stats_nba.possessions.web.StatsNbaPossessionWebLoader(file_directory=None)[source]

Bases: object

A StatsNbaPossessionWebLoader object should be instantiated and passed into StatsNbaPossessionLoader 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 stats_<game_id>.json in the /pbp subdirectory. If not provided response data will not be saved on disk.