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.11.tar.gz (33.9 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.11-py3-none-any.whl (39.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pbpstats-0.0.11.tar.gz
  • Upload date:
  • Size: 33.9 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.11.tar.gz
Algorithm Hash digest
SHA256 86563afdb703c9db6f3bf56227795e90a2f557ea65efa8394769d1dca44f09e3
MD5 1598ef2762e0f4f54c613672248d50ba
BLAKE2b-256 22f43002193409d6c7b7a6ede90f5068b756518b8b67fce1395e7b2d97799c50

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pbpstats-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 39.0 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.11-py3-none-any.whl
Algorithm Hash digest
SHA256 6bdedcb715b764bd8b63f61c48708314a55cdc664ec15ac38f6f7fe0582d4f6a
MD5 0e4aba6ebc8fb1b0700aa1cdda0efa31
BLAKE2b-256 f32923ea366d4018c8f24b72c0d959f2dcdd7aeb7f9c831d9dc19d223c5af2ae

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