Giter Site home page Giter Site logo

jtpavlock / nbapy Goto Github PK

View Code? Open in Web Editor NEW
11.0 5.0 4.0 370 KB

Python API for stats.nba.com

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%
nba nba-stats nba-api nba-stats-api nba-statistics python-3 sports-data sports-stats basketball basketball-stats

nbapy's Introduction

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

Documentation

A constant work-in-progress, but check them out!

Installation

To install from pypi:

$ python -m pip install nbapy

Contributing

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

2. Install development requirements

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.

3. Hack away

Coding conventions

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.

4. Create some tests

5. Make sure everything looks good

$ 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.

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.

nbapy's People

Contributors

actions-user avatar huyqle3 avatar insightpeter avatar jtpavlock avatar lentils avatar marek5050 avatar mcdallas avatar mwilliammyers avatar proche90210 avatar rgreasons avatar rymc9384 avatar seemethere avatar spancypantz avatar spudfkc avatar swar avatar trevormccormick avatar vitamintk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nbapy's Issues

Request Time out for any API call

Hey I am picking back up my project and was using this code again. I notice now that any API call I make times out. Are you seeing that also?

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)

Need Help Looping thru BoxScores

i am trying just to get 2nd dataframe in the return, and loop thru all games

from nbapy import game
game_id = '0021900017'
stats = game.BoxScore(game_id).players_stats()

New to Python but have question for you

Hey man thanks so much for sharing this repo! It's been great for me doing some exploratory analysis. I am running into a timeout issue though which I think might be a function of the NBA stats side. I am trying to get the player information for all NBA players. Your documentation allowed me to get the information for an individual player very easily. I am looping through to get for all players and am consistently running into a timeout issue. Do you know if the NBA stats prohibits this type of behavior? Or could I change the timeout setting myself?

summary = Summary(1629027)
summary.info()

Running Box Score example

When executing
pd.DataFrame(game.BoxScore(game_id).players_stats())
there seems to be an exceptionally long execution time with no output.
Is this package still useable?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.