Python API wrapper for stats.nba.com with a focus on NBA and WNBA applications
Project description
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.
Current Documentation
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):
- BoxScore
- Draft
- Image
- LeaderBoard
- League
- LeagueDash
- LeagueHustle
- PlayByPlay
- Player
- Salaries (using Hoopshype)
- ScoreBoard
- Shots
- Team
- WinProbability
Development
Initially map stats.nba.com API and fully document code.Refactor code to generate a more consistent structure across classes.Document endpoints and parameters with definitions.(See Wiki here)- Research other basketball-related APIs to map.
Write unit tests for the package.Begin introductory basketball analytics analyses.
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_!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file py_ball-1.41.tar.gz
.
File metadata
- Download URL: py_ball-1.41.tar.gz
- Upload date:
- Size: 88.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f33575a58243d40ab77d384d77b1183f02aea6b1772e31031d9791855cbb6ae |
|
MD5 | 56d885acb57107a154dd56c6914562c6 |
|
BLAKE2b-256 | 9bacf3bafa5582621fe27692f9da98fb9f2fd7e25aef170699a78f1fb7f32dff |
File details
Details for the file py_ball-1.41-py3-none-any.whl
.
File metadata
- Download URL: py_ball-1.41-py3-none-any.whl
- Upload date:
- Size: 106.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a40b47bc3a95d1225e7ee8f7dc53e555641379267914582eaf23171914ae3bbb |
|
MD5 | 8c512964131abb34112ecad23ccab04e |
|
BLAKE2b-256 | 2b4132601ad35de398758b2b37c9f970040c4fc8a7b325469e29f10097a3799b |