nbapy - stats.nba.com API for python
A python facing API for stats.nba.com
Warning stats.nba.com
is notorious for being extremely unreliable. Please report any issues you find.
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 = game.BoxScore(game_id).players_stats()
print(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 = game.BoxScore(game_id).players_stats()
print(stats)
A constant work-in-progress, but check them out!
To install from pypi:
$ python -m pip install nbapy
You will to first install poetry if you don't already have it.
$ python -m pip install poetry
After that, just run poetry install
inside of your fork.
Coding conventions
- black for formatting
- google docstrings
- flake8 for linting
- mypy for static typing analysis
- conventional commits for commit style.
- isort for import organization.
Whew, that's a lot, but I'm a big fan of clean code, and I hope you are too! The good news is that if you follow the following advice, you'll find these aren't too hard to manage 😄
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 commitizen. It is automatically installed in the dev dependencies, so to commit, you just run cz c
and follow the prompts.
If you're using pre-commit, and either the black or isort check fails, the good news is it will fix the problems for you. However, it won't continue the commit automatically so that you get a chance to look over the changes. You'll have to re-stage the changes, and then you can run cz c --retry
so you don't lose that nice commit message you just wrote.
$ pytest --cov
*
$ sphinx-build -n -W -q -b html docs docs/_build/html
$ 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.
Other ways to contribute involve submitting any issues or adding some documentation!
- Finish Jupyter Notebook documentation
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.