nba-api is a free and active Python client package designed to access statistics from the Official NBA stats page (nba.com). It provides a robust interface for developers to retrieve data on NBA teams, seasons, players, and games in various formats, including pandas DataFrames. The library is actively maintained with frequent updates to adapt to changes in the underlying NBA.com API.
pip install nba-apiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to fetch a player's ID using the static module and then retrieve their career statistics from an endpoint. It shows how to access the data as a pandas DataFrame, which is a common and convenient way to work with the results.
Review the `nba-api` release notes for removed and deprecated endpoints. Migrate your code to use the recommended `V3` versions (e.g., `BoxScorePlayerTrackV3`, `PlayByPlayV3`, `ScoreboardV3`) or alternative endpoints.
Upgrade `nba-api` to version 1.11.4 or newer. This version includes updated request headers to ensure compatibility with NBA.com's API.
After upgrading to v1.11.2+, verify the order of datasets returned by affected `BoxScore` endpoints using `endpoint.get_data_frames()`. Adjust your indexing (`[0]`, `[1]`, etc.) accordingly to match the corrected order.
Implement delays (e.g., `time.sleep(1)` to `time.sleep(3)`) between requests, particularly when looping through multiple API calls. For cloud deployments, consider using proxies as NBA.com may block known cloud IP ranges.
Update your code to use the replacement endpoint, `BoxScorePlayerTrackV3`. For other removed endpoints like `PlayerFantasyProfile`, there may not be a direct replacement; refer to `nba-api` release notes for guidance.
Upgrade `nba-api` to v1.11.4+ for updated headers. If the issue persists, introduce `time.sleep()` delays between requests (e.g., 1-3 seconds) and consider running from a local IP or using proxies if deployed on a cloud server.
Ensure you are using `nba-api` v1.11.2 or newer. After calling an endpoint, inspect the list of DataFrames returned by `get_data_frames()` (e.g., `endpoint.get_data_frames()`) to confirm the current order and adjust your indexing accordingly. For example, player stats might be `[0]` and team stats `[1]`.