Skip to main content

Python client for NBA statistics located at nba.com

Project description

Actions Status PyPI Downloads

nbapy - stats.nba.com API for python

Summary

A python facing API for stats.nba.com

Warning stats.nba.com is notorious for being extremely unreliable. Please report any issues you find.

Usage

All data is returned as a pandas dataframe (check out the starter docs if you're new to pandas). For example:

from nbapy import game
import pandas as pd

game_id = '0021900017'  # taken from 'https://stats.nba.com/game/0021900017/'
stats = pd.DataFrame(game.BoxScore(game_id).players_stats())

If you want to cache results so you don't have to reach the api every time, you can use requests-cache

from nbapy import game
import pandas as pd
import requests_cache

requests_cache.install_cache('nbapy_cache')

game_id = '0021900017'
stats = pd.DataFrame(game.BoxScore(game_id).players_stats())

Documentation

An ongoing process, but check out the jupyter notebook docs, or feel free to poke around the codebase.

Installation

To install from pypi:

$ python -m pip install nbapy

Else:

  • Download from source (git clone, zipped package)
  • Run from the root directory:
$ python -m pip install .

Contributing

1. Fork the repository and create a feature/bug fix branch

2. Install development requirements

$ python -m pip install -e . ".[dev]"

3. Hack away

Coding conventions

Optional (but recommended)

nbapy has a pre-commit file that you can install to automatically enforce these conventions prior to committing via a git hook.

To install: $ pre-commit install

You can also use $ pre-commit run -a to run the checks manually.

For commit messages, I recommend using commtizen. It is automatically installed in the dev dependencies, so to commit, you just run cz c and follow the prompts.

4. Create some tests

5. Make sure everything looks good

$ pytest --cov*

$ pre-commit run -a (if you didn't install the pre-commit git hook)

* note the first time you run this, it may take a few minutes. However, the requests will cache, and subsequent runs should be much faster.

6. Submit a pull request

Other ways to contribute involve submitting any issues or adding some documentation!

To-Do

  • Finish Jupyter Notebook documentation

Authors

This is orginally based off of https://github.com/seemethere/nba_py so a lot of the work was done by those guys. My goal with this project is to clean up the code, add some proper documentation, and keep it up to date.

Project details


Download files

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

Files for nbapy, version 1.1.8
Filename, size File type Python version Upload date Hashes
Filename, size nbapy-1.1.8-py3-none-any.whl (22.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size nbapy-1.1.8.tar.gz (19.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page