Skip to main content

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.

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):

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_!

Release files for py-ball 1.42

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-ball 1.42
File Size Uploaded
py_ball-1.42.tar.gz 88.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-ball 1.42
File Interpreter ABI Platform
py_ball-1.42-py3-none-any.whl Python 3 none any Details

Total release size: 195.4 kB

Release files / py_ball-1.42.tar.gz

Download URL py_ball-1.42.tar.gz
Size 88.3 kB
Tags Source
SHA-256 checksum
How to use checksums
82a9ca7b01b71f59d2fb68f6345e3b33fa897df76f374a7996ffc833612b9b61
BLAKE2b-256 checksum
How to use checksums
59d166d7c47174b0eb500f2fb516707fba6e1e25088284661d51ad9f65681166
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.10

Release files / py_ball-1.42-py3-none-any.whl

Download URL py_ball-1.42-py3-none-any.whl
Size 107.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b6aa4ad100e504698738d465462413a69943d84400fa79a02fd313efb0225729
BLAKE2b-256 checksum
How to use checksums
9e716efe0e484419c208d9b48ecf76b4a3970a6ac98c9792d88c2181179291a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.10

Release history Release notifications | RSS feed

This release

1.42 This release

2 release files

1.41

2 release files

1.4

2 release files

1.3

1 release file

1.2

2 release files

1.1

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

1 release file

1.0.1

1 release file

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page