nba_api Documentation

repository·master·Indexed 25 days ago

https://github.com/swar/nba_api

An API client package for accessing NBA.com APIs. It provides tools to retrieve official NBA statistics via the nba_api.stats.endpoints module, returning data as Pandas DataFrames, JSON objects, or Python dictionaries. The library includes the NBAResponse class for handling API responses, the NBAHTTP class for executing requests, and support for proxy configuration, request logging, and debug modes.

Tokens
201.6K
Snippets
172
Records
628
Agent score
85%

What's inside nba_api

  1. Explore NBA API endpoints and tools

    master

    The nba_api package provides a comprehensive suite of tools and endpoints to access NBA.com data. You can use the library to access official stats (via stats.nba.com), live data, and static information like player and team lists.

    Key areas of the documentation include:

    • Library Core: Debugging tools and HTTP utilities.
    • Stats API: Extensive endpoints for player/team performance, shot charts, and league-wide statistics.
    • Static Data: Access to player and team metadata.
    • Tools: Utilities for endpoint analysis and documentation generation.
  2. Use analyze_endpoints_and_create_files.py for endpoint generation

    master

    The analyze_endpoints_and_create_files.py script can be used to analyze all endpoints and automatically generate .py files, endpoint documentation, and parameter documentation.

    Warning: This script is sensitive to changes in the NBA API and may break if major changes occur in the underlying API structure.

    When troubleshooting or debugging the generation process, it is recommended to enable DEBUG and DEBUG_STORAGE settings.

  3. Install nba_api

    master

    Install the nba_api package using pip. The package requires Python 3.10+ and the requests and numpy packages. If you want to work with Pandas DataFrames, you must also install pandas.

    pip install nba_api
  4. Enable request logging with `DEBUG_STORAGE`

    master

    Set DEBUG_STORAGE to True to save every request to a text file. Files are saved in a debug_storage folder, with filenames generated by joining parameters and using an MD5 hash.

    Note: This feature requires DEBUG to be set to True to function.

  5. Access NBA Official Stats

    master
    Use the nba_api.stats.endpoints module to access official NBA statistics. Endpoints return data that can be accessed as a Pandas DataFrame (if pandas is installed), a JSON object, or a Python dictionary.
  6. Access data from stats endpoints as JSON, dictionary, or DataFrame

    master

    Every stats endpoint instance contains one or more DataSet objects (e.g., available_seasons, common_player_info). You can retrieve the data from a specific DataSet using the following methods:

    • get_json(): Returns data as a JSON string.
    • get_dict(): Returns data as a Python dictionary.
    • get_data_frame(): Returns the data set as a pandas DataFrame (requires pandas to be installed).