Modules

matchups

nba_stats_tracking.matchups.get_matchup_results_for_game_id(game_id)[source]

Makes API call to NBA Advanced Stats and returns MatchupResults object

Parameters

game_id (str) – nba.com game id

Returns

matchup results

Return type

MatchupResults

tracking

nba_stats_tracking.tracking.aggregate_full_season_tracking_stats_for_seasons(measure_type, seasons, season_types, player_or_team, **kwargs)[source]

Aggregates full season stats for stat measure for desired filters. Returns list of ResultItem for stats for each team/player and ResultItem with league totals.

Parameters
  • measure_type (TrackingMeasureType) – Stat measure type to get stats for

  • seasons (List[str]) – List of seasons. Format YYYY-YY ex 2019-20

  • season_types (List[SeasonType]) – List of season types.

  • player_or_team (PlayerOrTeam) – get stats for player or team

  • OpponentTeamID (str) – (optional) nba.com team id

Return type

Tuple[List[Any], Any]

nba_stats_tracking.tracking.generate_tracking_game_logs(measure_type, player_or_team, date_from, date_to, **kwargs)[source]

Generates game logs for all games between two dates for desired filters Returns list of game log ResultItem

Parameters
  • measure_type (TrackingMeasureType) – Stat measure type to get stats for

  • player_or_team (PlayerOrTeam) – get stats for player or team

  • date_from (date) – start date

  • date_to (date) – end date

  • team_id_game_id_map (dict) – (optional) dict mapping team id to game id. When getting game logs for multiple separate filters for the same date it is recommended that you pass this in to avoid making the same request multiple times

  • team_id_opponent_team_id_map (dict) – (optional) dict mapping team id to opponent team id. When getting game logs for multiple separate filters for the same date it is recommended that you pass this in to avoid making the same request multiple times

  • player_id_team_id_map (dict) – (optional) dict mapping player id to team id. When getting game logs for multiple separate filters for the same date it is recommended that you pass this in to avoid making the same request multiple times

Return type

List[Any]

nba_stats_tracking.tracking.get_tracking_results_for_stat_measure(measure_type, season, season_type, player_or_team, **kwargs)[source]

Makes API call to NBA Advanced Stats and returns JSON response results

Parameters
  • measure_type (TrackingMeasureType) – Stat measure type to get stats for

  • season (str) – Format YYYY-YY ex 2019-20

  • season_type (SeasonType) – Season type to get stats for

  • player_or_team (PlayerOrTeam) – get stats for player or team

  • DateFrom (str) – (optional) Format - MM/DD/YYYY

  • DateTo (str) – (optional) Format - MM/DD/YYYY

  • OpponentTeamID (str) – (optional) nba.com team id

  • PerMode (PerMode) – (optional) Defaults to totals.

Returns

response json

Return type

dict

nba_stats_tracking.tracking.get_tracking_stats(measure_type, seasons, season_types, player_or_team, **kwargs)[source]

Gets stat measure tracking stats for filter Returns list of ResultItem with stats for each player/team

Parameters
  • measure_type (TrackingMeasureType) – Stat measure type to get stats for

  • seasons (List[str]) – List of seasons. Format YYYY-YY ex 2019-20

  • season_types (List[SeasonType]) – List of season types.

  • player_or_team (PlayerOrTeam) – get stats for player or team

  • DateFrom (str) – (optional) Format - MM/DD/YYYY

  • DateTo (str) – (optional) Format - MM/DD/YYYY

  • OpponentTeamID (str) – (optional) nba.com team id

  • PerMode (PerMode) – (optional) Defaults to totals.

Return type

List[Any]

nba_stats_tracking.tracking.sum_tracking_totals(entity_type, measure_type, *args)[source]

Sums totals for given dicts and grouped by entity type Returns list of ResultItem with totals for each entity or ResultItem if entity type is league

Parameters
  • entity_type (str) – Options are Player, Team or league

  • measure_type (TrackingMeasureType) – Stat measure type to get stats for

  • *args – Variable length argument list of ResultItem to be summed up

Return type

Union[List[Any], Any]

tracking_shots

helpers

nba_stats_tracking.helpers.get_boxscore_response_for_game(game_id)[source]

Gets response data from boxscore endpoint for nba.com game id

Return type

Dict

nba_stats_tracking.helpers.get_game_ids_for_date(game_date)[source]

Gets game ids for all games played on a given date

Return type

List[str]

nba_stats_tracking.helpers.get_json_response(url, params)[source]

Helper function to get json response for request

Return type

Dict

nba_stats_tracking.helpers.get_player_team_map_for_date(game_date)[source]

Creates a dict mapping player id to team id for all games on a given date

Return type

Dict

nba_stats_tracking.helpers.get_scoreboard_response_json_for_date(game_date)[source]

Gets response data for scoreboard endpoint

Return type

Dict

nba_stats_tracking.helpers.get_season_from_game_id(game_id)[source]

Gets season from nba.com game id 4th and 5th digits of game id represent year season started ex 0021900001 is for the 2019-20 season

Return type

str

nba_stats_tracking.helpers.get_season_type_from_game_id(game_id)[source]

Gets season type from nba.com game id Season type is represented in 3rd digit of game id 2 is Regular Season, 4 is Playoffs

Return type

SeasonType

nba_stats_tracking.helpers.get_team_id_maps_for_date(game_date)[source]

Creates dicts mapping team id to game id and team id to opponent team id for games on a given date

Return type

Tuple[Dict, Dict]

nba_stats_tracking.helpers.make_player_team_map_for_game(boxscore_data)[source]

Creates a dict mapping player id to team id for a game

Return type

Dict