• Stars
    star
    102
  • Rank 333,697 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python API for stats.nba.com with a focus on NBA and WNBA applications

Downloads

py_ball

Python API wrapper for stats.nba.com with a focus on NBA and WNBA applications

Introduction

The motivation for this stems from nba_py by seemethere and nbastatsR by abresler. The work towards a Python API wrapper in nba_py is a great start, but the documentation of the stats.nba.com API is lacking. nbastatsR is an extremely valuable resource for the R community, and this work hopes to extend the breadth and depth of that package. In my research, I have also come across the recent effort of nba_api by swar. This looks similar to nba_py and I am hoping to collaborate.

Goals

If successful, py_ball should accomplish the following:

  • By working with the community, improve the quality of documentation for stats.nba.com.
  • Further enable the dissemination of basketball statistics to increase the understanding of the sport and encourage the practice of basketball analytics.
  • Produce introductory analyses leveraging NBA and WNBA data to reduce the barrier of entry to basketball analytics through demonstration.
  • Focus on the WNBA in an effort to stress inclusivity and contribute to women's basketball analytics.

Documentation

While nba_api improves greatly upon the documentation of the stats.nba.com API in nba_py, py_ball strives to take documentation further through the following:

  • Fully documented code, including function, class, and script docstrings.
  • Extend endpoint and parameter documentation to include feature definitions.

Classes:

The functionality of the classes within the package are documented in both the docstrings and this site. The endpoints, parameters, and tables are documented in the Wiki (linked below):

Development

  1. Initially map stats.nba.com API and fully document code.
  2. Refactor code to generate a more consistent structure across classes.
  3. Document endpoints and parameters with definitions. (See Wiki here)
  4. Research other basketball-related APIs to map.
  5. Write unit tests for the package.
  6. Begin introductory basketball analytics analyses.
    • Franchise History (here!)
    • Draft Combine Player Sheet (here!)
    • Live NBA/WNBA scoreboard (here!)
    • Shot Probability Model (here!)
    • Location Data Exploration (here!)
    • Assist Networks (here!)
    • Win Probability Model (here!)

Installation

The package is built for Python 3 and leverages the packages in the requirements.txt file. py_ball can be installed via pip (more info here):

pip install py_ball

Usage

The stats.nba.com API requires a request header for all API calls. A good discussion on this, including steps to obtain a proper request header, can be found here. With a request header in HEADER, the example below demonstrates usage of the package to pull franchise history for the WNBA:

from py_ball import league, image

league_id = '10' #WNBA
franchises = league.League(headers=HEADERS,
                           endpoint='franchisehistory',
                           league_id=league_id)

Each class, with the exception of the Headshot and Logo classes, has a data attribute. This is a dictionary containing table names as keys and a list of dictionaries of table data as values. The Headshot and Logo classes have an image attribute that is a PNG object.

Contact

Follow along for updates or reach out on Twitter @py_ball_!

More Repositories

1

basketball_data_science

Working through Basketball Data Science
Jupyter Notebook
23
star
2

shot_probability

Building a shot probability model from NBA shot chart data
Jupyter Notebook
11
star
3

location_data

Generating shot, foul, and assist charts
Jupyter Notebook
11
star
4

challenges

Exploratory data analysis of the new NBA challenge rule
Jupyter Notebook
5
star
5

draft_combine

NBA Draft Combine Analysis
Jupyter Notebook
5
star
6

synergy

NBA Synergy data exploration
Jupyter Notebook
3
star
7

scoreboard

Using Jupyter to build a dashboard displaying a basketball scoreboard
Jupyter Notebook
3
star
8

l2m

NBA Last Two Minute Report exploration
Jupyter Notebook
3
star
9

ETM

Basketball Metric Development
R
2
star
10

nba_lottery

Tool to simulate the NBA lottery as teams are revealed
Jupyter Notebook
2
star
11

assist_networks

Visualizing team assists as a network of player nodes
Jupyter Notebook
2
star
12

franchise_history

WNBA and NBA franchise history visualization
Jupyter Notebook
2
star
13

personal

Personal website
HTML
1
star
14

video

Accessing play-by-play video
1
star
15

defense

Visualizing and quantifying defensive impact
Jupyter Notebook
1
star
16

team_travel

Visualizing and quantifying NBA team travel
Jupyter Notebook
1
star
17

basketballrelativity.github.io

HTML
1
star
18

team_additions

Visualizing team and player statistics in the context of transactions
Jupyter Notebook
1
star
19

playing_time_viz

Visualizing playing time throughout WNBA and NBA games
1
star
20

salaries

Exploratory Analysis of NBA Salary Data
Jupyter Notebook
1
star
21

rebounding

Visualizing and quantifying rebounding
1
star
22

wnba_lottery

Tool to provide updated odds by team for the WNBA lottery as teams are revealed
Jupyter Notebook
1
star
23

win_probability

Developing NBA and WNBA in-game win probability models
Jupyter Notebook
1
star
24

nba_lottery_site

Site to host live NBA Draft Lottery Odds
Python
1
star
25

approach

Modeling expected strokes as a function of distance from the hole and lie type
Jupyter Notebook
1
star
26

nyc_bb

Visualization of New York City Public Basketball Courts
Jupyter Notebook
1
star
27

bball-analytics

Jupyter Notebook
1
star