An API Client package to access the APIs for NBA.com
翻譯準備中
開發工具Python · ShellGitHub @swar自行安裝營運者未確認
試用過了嗎? 點一下就好,不需要登入。
製作者的介紹僅有上面的一句話。 更多詳情請閱讀儲存庫 README。 儲存庫 README ↗
正在載入完整 README。
檢視完整 README ↗The NBA's stats, in Python. nba_api wraps 130+ stats.nba.com endpoints and the live game feeds behind NBA.com, no API key required, and hands stats back as pandas DataFrames.
league_idpip install nba_api
Requires Python 3.10+. Installs requests and pandas.
Player and team reference data ships with the package, so lookups are instant and work offline.
from nba_api.stats.static import players, teams
players.find_players_by_full_name("donovan mitchell")
# [{'id': 1628378, 'full_name': 'Donovan Mitchell', 'first_name': 'Donovan',
# 'last_name': 'Mitchell', 'is_active': True}]
teams.find_team_by_abbreviation("cle")
# {'id': 1610612739, 'full_name': 'Cleveland Cavaliers', 'abbreviation': 'CLE', ...}
Searches take case-insensitive regular expressions, and player name searches ignore accents ("žydrūnas" finds "Zydrunas Ilgauskas").
stats.nba.comfrom nba_api.stats.endpoints import playercareerstats
career = playercareerstats.PlayerCareerStats(player_id=1628378) # sends the request
df = career.season_totals_regular_season.get_data_frame()
df[["SEASON_ID", "TEAM_ABBREVIATION", "PTS"]].tail(3)
# SEASON_ID TEAM_ABBREVIATION PTS
# 6 2023-24 CLE 1463
# 7 2024-25 CLE 1701
# 8 2025-26 CLE 1952
Every stats endpoint works the same way: constructing it sends the request, and each data set it returns is an attribute with get_data_frame(), get_dict(), and get_json(). To grab everything at once, use career.get_data_frames() or career.get_dict(). To find the endpoint that has the data you want, see the endpoint guide. The endpoint reference lists every endpoint's parameters and data sets.
cdn.nba.comfrom nba_api.live.nba.endpoints import scoreboard
games = scoreboard.ScoreBoard() # today's games
cavs = [
g for g in games.games.get_dict()
if "CLE" in (g["homeTeam"]["teamTricode"], g["awayTeam"]["teamTricode"])
] # tonight's Cavs game, if they play
Live endpoints: ScoreBoard, BoxScore(game_id), PlayByPlay(game_id), and Odds. They return dicts and JSON.
Every endpoint, stats or live, accepts the same request options:
career = playercareerstats.PlayerCareerStats(
player_id=1628378,
timeout=60, # seconds; default 30
proxy="http://127.0.0.1:8080", # or a list of proxies to pick from at random
headers={"User-Agent": "..."}, # replaces the default headers entirely
get_request=False, # build the request without sending it
)
career.get_request() # send it later
Requests hanging or timing out?
stats.nba.comthrottles rapid requests and does not respond to many cloud-hosting IP ranges (AWS, GCP, Azure, Colab, and others).
time.sleep(1).timeout.proxy, or set the NBA_API_PROXY environment variable.More detail is in the stats examples.
nba-api.Contributions of all sizes are welcome, from fixing a typo to adding an endpoint. See CONTRIBUTING.md to set up a development environment and open a pull request.
NBA.com does not announce new, changed, or removed endpoints. If you find one, or hit a bug, open an issue.
nba_api is open source under the MIT License.
Data retrieved with this package comes from NBA.com and is subject to the NBA.com Terms of Use.
nba_api is an independent, community-maintained project and is not affiliated with, endorsed by, or sponsored by the NBA.