Skip to main content

A package to scrape and parse NBA, WNBA and G-League play-by-play data

Project description

Build Status PyPI version Downloads

A package to scrape and parse NBA, WNBA and G-League play-by-play data.

Features

  • Adds lineup on floor for all events
  • Adds detailed data for each possession including start time, end time, score margin, how the previous possession ended, second chance time, offensive rebounds
  • Shots, rebounds and assists broken down by shot zone
  • Supports both stats.nba.com and data.nba.com endpoints
  • Supports NBA, WNBA and G-League stats
  • All stats on pbpstats.com are derived from these stats

Installation

requires Python >=3.6

pip install pbpstats

Setup data directory

There will be cases where events may be out of order or incorrect due to human error. If you want to be able to manually edit events you can set up the enivronment variable PBP_STATS_DATA_DIRECTORY and all request responses will be saved locally so edits can be made. If a file for a game exists locally it will be used instead of making the request to the NBA API. This directory is also where override files to fix periods starters and handle issues with parsing pbp that can't be fixed by editing pbb file are placed.

Usage

from pbpstats.stats_game_data import StatsGameData

game_data = StatsGameData('0041800406')
game_data.get_game_data()
# to ignore rebound event order
# game_data.get_game_data(ignore_rebound_and_shot_order=True)
# to ignore issues parsing pbp that result in a team having back-to-back possessions
# game_data.get_game_data(ignore_back_to_back_possessions=True)

to get player stats for game:

player_stats = game_data.get_aggregated_possession_stats_for_entity_type('player')

to get team stats for game:

team_stats = game_data.get_aggregated_possession_stats_for_entity_type('team')

to get opponent stats for game:

opponent_stats = game_data.get_aggregated_possession_stats_for_entity_type('opponent')

to get lineup stats for game:

lineup_stats = game_data.get_aggregated_possession_stats_for_entity_type('lineup')

to get lineup opponent stats for game:

lineup_opponent_stats = game_data.get_aggregated_possession_stats_for_entity_type('lineupopponent')

to see data for specific possession

print(game_data.Periods[0].Possessions[14])

Note on Ids

Player and team Ids the same player and team ids used by stats.nba.com. Lineup ids are '-' separated player ids (with player ids sorted as strings).

Issues with raw play-by-play

See here for how to edit and fix common issues with play-by-play data.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pbpstats-0.0.3.tar.gz (33.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pbpstats-0.0.3-py3-none-any.whl (37.9 kB view details)

Uploaded Python 3

File details

Details for the file pbpstats-0.0.3.tar.gz.

File metadata

  • Download URL: pbpstats-0.0.3.tar.gz
  • Upload date:
  • Size: 33.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

File hashes

Hashes for pbpstats-0.0.3.tar.gz
Algorithm Hash digest
SHA256 1f03a35c8415e5cb051c662f2c3a341ec9a06845da91207c9627d94966d3041d
MD5 36673a30d2435a75bbaf385d2a39cf14
BLAKE2b-256 42db34cf9a2f1cecc21c9b3a3374fe5503c0648478108e0a076abe38e7f6fd07

See more details on using hashes here.

File details

Details for the file pbpstats-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: pbpstats-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 37.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

File hashes

Hashes for pbpstats-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a47b03f65ae07cfd3bf90cf348d2bea9c78613991728e3e60e2d63d07ab24bc2
MD5 b89cdad0f41da344fe9727d45ddb7e00
BLAKE2b-256 ff2eea73a96636e4298f80e10f8b269728e292dc1960e9ac71c8bc4104e1b4a7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page