├── tools
├── __init__.py
├── stats
│ ├── __init__.py
│ ├── library
│ │ └── __init__.py
│ ├── endpoint_analysis
│ │ └── __init__.py
│ ├── endpoint_py_file_generator
│ │ ├── __init__.py
│ │ └── template.py
│ ├── endpoint_documentation_generator
│ │ ├── __init__.py
│ │ └── template.py
│ └── parameter_documentation_generator
│ │ ├── __init__.py
│ │ └── template.py
└── library
│ ├── __init__.py
│ ├── file_handler.py
│ └── functions.py
├── tests
├── unit
│ ├── stats
│ │ ├── __init__.py
│ │ └── endpoints
│ │ │ ├── __init__.py
│ │ │ ├── data
│ │ │ ├── __init__.py
│ │ │ └── teamdashlineups.py
│ │ │ └── test_teamgamelog.py
│ ├── test_static_data.py
│ ├── test_eventmsgtype.py
│ ├── test_stats_endpoints_base.py
│ └── test_http.py
├── __init__.py
└── integration
│ ├── __init__.py
│ ├── data
│ ├── __init__.py
│ ├── scoreboardv3.py
│ ├── playerdashptshotdefend.py
│ ├── teamgamelog.py
│ ├── teamdashlineups.py
│ ├── leaguedashteamstats.py
│ └── teamgamelogs.py
│ ├── test_stats_endpoints_responses_valid.py
│ └── test_stats_library_playbyplayregex.py
├── src
└── nba_api
│ ├── library
│ ├── __init__.py
│ ├── debug
│ │ ├── __init__.py
│ │ └── debug.py
│ └── _enum_base.py
│ ├── live
│ ├── __init__.py
│ └── nba
│ │ ├── __init__.py
│ │ ├── library
│ │ ├── __init__.py
│ │ └── http.py
│ │ └── endpoints
│ │ ├── __init__.py
│ │ └── _base.py
│ ├── stats
│ ├── __init__.py
│ ├── library
│ │ ├── __init__.py
│ │ ├── eventmsgtype.py
│ │ └── parserv3.py
│ ├── static
│ │ └── __init__.py
│ └── endpoints
│ │ ├── _expected_data
│ │ ├── __init__.py
│ │ ├── dunkscoreleaders.py
│ │ └── scoreboardv3.py
│ │ ├── videoevents.py
│ │ ├── videoeventsasset.py
│ │ ├── commonteamyears.py
│ │ ├── _parsers
│ │ └── iststandings.py
│ │ ├── playerawards.py
│ │ ├── shotchartleaguewide.py
│ │ ├── commonplayoffseries.py
│ │ ├── draftcombinedrillresults.py
│ │ ├── assistleaders.py
│ │ ├── videostatus.py
│ │ ├── franchiseleaders.py
│ │ ├── draftcombineplayeranthro.py
│ │ ├── playbyplay.py
│ │ ├── infographicfanduelplayer.py
│ │ ├── teamhistoricalleaders.py
│ │ ├── commonallplayers.py
│ │ ├── gamerotation.py
│ │ ├── winprobabilitypbp.py
│ │ ├── playernextngames.py
│ │ ├── franchisehistory.py
│ │ ├── glalumboxscoresimilarityscore.py
│ │ ├── playbyplayv3.py
│ │ ├── cumestatsplayergames.py
│ │ ├── drafthistory.py
│ │ ├── franchiseplayers.py
│ │ ├── cumestatsteamgames.py
│ │ ├── draftboard.py
│ │ ├── playercareerbycollege.py
│ │ ├── boxscoredefensivev2.py
│ │ ├── commonteamroster.py
│ │ ├── playergamelog.py
│ │ ├── teamestimatedmetrics.py
│ │ ├── teamyearbyyearstats.py
│ │ └── teamgamelog.py
│ └── __init__.py
├── poetry.toml
├── docs
├── nba_api
│ ├── stats
│ │ ├── endpoints_output
│ │ │ ├── assisttracker_output.md
│ │ │ ├── glalumboxscoresimilarityscore_output.md
│ │ │ ├── playerdashptshotdefend_output.md
│ │ │ ├── draftboard_output.md
│ │ │ ├── assistleaders_output.md
│ │ │ ├── cumestatsteamgames_output.md
│ │ │ ├── cumestatsplayergames_output.md
│ │ │ ├── franchiseleaders_output.md
│ │ │ ├── teamhistoricalleaders_output.md
│ │ │ ├── commonteamyears_output.md
│ │ │ ├── commonplayoffseries_output.md
│ │ │ ├── playerfantasyprofilebargraph_output.md
│ │ │ ├── shotchartleaguewide_output.md
│ │ │ ├── teaminfocommon_output.md
│ │ │ ├── homepageleaders_output.md
│ │ │ ├── leaderstiles_output.md
│ │ │ ├── leaguedashptteamdefend_output.md
│ │ │ ├── playergamestreakfinder_output.md
│ │ │ ├── teamgamestreakfinder_output.md
│ │ │ ├── commonplayerinfo_output.md
│ │ │ ├── leaguedashptstats_output.md
│ │ │ ├── playerawards_output.md
│ │ │ ├── playercareerbycollege_output.md
│ │ │ ├── leaguedashptdefend_output.md
│ │ │ ├── leaguedashoppptshot_output.md
│ │ │ └── leaguedashteamptshot_output.md
│ │ ├── library
│ │ │ └── data.md
│ │ ├── endpoints_data_structure.md
│ │ └── endpoints
│ │ │ ├── videoevents.md
│ │ │ ├── commonteamyears.md
│ │ │ ├── playerawards.md
│ │ │ ├── shotchartleaguewide.md
│ │ │ ├── commonplayoffseries.md
│ │ │ ├── franchiseleaders.md
│ │ │ ├── draftcombinedrillresults.md
│ │ │ ├── videostatus.md
│ │ │ └── draftcombineplayeranthro.md
│ ├── tools
│ │ └── stats
│ │ │ ├── endpoint_py_file_generator
│ │ │ └── generator.md
│ │ │ ├── endpoint_documentation_generator
│ │ │ └── generator.md
│ │ │ ├── input_output_definitions.md
│ │ │ └── parameter_documentation_generator
│ │ │ └── generator.md
│ ├── debug.md
│ └── library
│ │ └── http.md
├── scripts.md
├── package_structure.md
└── endpoint_analysis_format.md
├── .deepsource.toml
├── .github
├── dependabot.yml
└── ISSUE_TEMPLATE
│ └── bug.yml
├── .vscode
└── settings.json
├── scripts
└── analyze_endpoints_and_create_files.py
├── LICENSE
├── .flake8
├── .devcontainer
├── post-create-command.sh
└── Dockerfile
├── .circleci
└── config.yml
├── .pylintrc
└── .gitignore
/tools/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tools/stats/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/unit/stats/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tools/library/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/nba_api/library/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/nba_api/live/__init__.py:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/nba_api/live/nba/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/nba_api/stats/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tools/stats/library/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/nba_api/library/debug/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/nba_api/stats/library/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/unit/stats/endpoints/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/nba_api/live/nba/library/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/unit/stats/endpoints/data/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tools/stats/endpoint_analysis/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/nba_api/__init__.py:
--------------------------------------------------------------------------------
1 | name = "nba_api"
2 |
--------------------------------------------------------------------------------
/tests/__init__.py:
--------------------------------------------------------------------------------
1 | """Tests for nba_api."""
2 |
--------------------------------------------------------------------------------
/tools/stats/endpoint_py_file_generator/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tools/stats/endpoint_documentation_generator/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tools/stats/parameter_documentation_generator/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/poetry.toml:
--------------------------------------------------------------------------------
1 | [virtualenvs]
2 | prefer-active-python = true
3 |
--------------------------------------------------------------------------------
/src/nba_api/stats/static/__init__.py:
--------------------------------------------------------------------------------
1 | __all__ = ["players", "teams"]
2 |
--------------------------------------------------------------------------------
/tests/integration/__init__.py:
--------------------------------------------------------------------------------
1 | """Endpoint validation tests for nba_api."""
2 |
--------------------------------------------------------------------------------
/tests/integration/data/__init__.py:
--------------------------------------------------------------------------------
1 | """Test data for endpoint validation."""
2 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/_expected_data/__init__.py:
--------------------------------------------------------------------------------
1 | """Expected data definitions for NBA Stats API endpoints."""
2 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/assisttracker_output.md:
--------------------------------------------------------------------------------
1 | AssistTracker:
2 |
3 | | ASSISTS |
4 | |----------:|
5 | | 57727 |
--------------------------------------------------------------------------------
/.deepsource.toml:
--------------------------------------------------------------------------------
1 | version = 1
2 |
3 | [[analyzers]]
4 | name = "python"
5 | enabled = true
6 |
7 | [analyzers.meta]
8 | runtime_version = "3.x.x"
--------------------------------------------------------------------------------
/tests/unit/test_static_data.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.static import teams
2 |
3 |
4 | def test_nba_teams():
5 | assert len(teams.teams) == 30
6 |
7 |
8 | def test_wnba_teams():
9 | assert len(teams.wnba_teams) == 13
10 |
--------------------------------------------------------------------------------
/src/nba_api/live/nba/endpoints/__init__.py:
--------------------------------------------------------------------------------
1 | __all__ = ["playbyplay", "boxscore", "scoreboard", "odds"]
2 |
3 | from .playbyplay import PlayByPlay
4 | from .boxscore import BoxScore
5 | from .scoreboard import ScoreBoard
6 | from .odds import Odds
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/glalumboxscoresimilarityscore_output.md:
--------------------------------------------------------------------------------
1 | GLeagueAlumBoxScoreSimilarityScores:
2 |
3 | | PERSON_2_ID | PERSON_2 | TEAM_ID | SIMILARITY_SCORE |
4 | |---------------|------------|-----------|--------------------|
--------------------------------------------------------------------------------
/src/nba_api/library/debug/debug.py:
--------------------------------------------------------------------------------
1 | DEBUG = False
2 |
3 | # Saving and loading responses from text files so that you do not have to do multiple requests when debugging.
4 | DEBUG_STORAGE = False
5 |
6 | # PROXY = ''
7 |
8 | # STATS_HEADERS = {}
9 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: "pip"
4 | directory: "/"
5 | schedule:
6 | interval: "weekly"
7 | commit-message:
8 | prefix: "chore"
9 | prefix-development: "chore"
10 | include: "scope"
11 | open-pull-requests-limit: 10
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/playerdashptshotdefend_output.md:
--------------------------------------------------------------------------------
1 | DefendingShots:
2 |
3 | | CLOSE_DEF_playerId | GP | G | DEFENSE_CATEGORY | FREQ | D_FGM | D_FGA | D_FG_PCT | NORMAL_FG_PCT | PCT_PLUSMINUS |
4 | |----------------------|------|-----|--------------------|--------|---------|---------|------------|-----------------|-----------------|
--------------------------------------------------------------------------------
/docs/scripts.md:
--------------------------------------------------------------------------------
1 | #`/scripts/`
2 |
3 | ## `analyze_endpoints_and_create_files.py`
4 |
5 | This is a script to analyze all endpoints and create the .py files, endpoint documentation, and parameter documentation. Please note that this file might break dependent on major changes to the NBA API.
6 |
7 | It will be beneficial to enable `DEBUG` and `DEBUG_STORAGE` to help in the debugging process.
8 |
--------------------------------------------------------------------------------
/tools/stats/parameter_documentation_generator/template.py:
--------------------------------------------------------------------------------
1 | header_template = """
2 | ## _{parameter_name}_
3 | """
4 |
5 | regex_pattern_body_template = """
6 | #### Class `{python_class}`
7 | ##### Patterns
8 | {regex_patterns}
9 | """
10 |
11 | regex_pattern_line_template = """ - `{pattern}`"""
12 |
13 |
14 | variable_body_template = """
15 | Variable Name | Value
16 | ------------ | -------------
17 | {variables}
18 | """
19 |
20 | variable_line_template = """_**{name}**_ {additional_tags}| `{value}`"""
21 |
--------------------------------------------------------------------------------
/tests/unit/test_eventmsgtype.py:
--------------------------------------------------------------------------------
1 | import warnings
2 | from nba_api.stats.library.eventmsgtype import EventMsgType
3 |
4 |
5 | def test_eventmsgtype():
6 | with warnings.catch_warnings(record=True) as w:
7 | # Invoke Deprecation Warning
8 | _ = EventMsgType.UNKNOWN
9 |
10 | assert len(w) == 1
11 |
12 | assert issubclass(w[0].category, DeprecationWarning)
13 | assert (
14 | str(w[0].message)
15 | == "'UNKNOWN' member is deprecated; use 'INSTANT_REPLAY' instead."
16 | )
17 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/draftboard_output.md:
--------------------------------------------------------------------------------
1 | DraftBoard:
2 |
3 | | PERSON_ID | PLAYER_NAME | SEASON | ROUND_NUMBER | ROUND_PICK | OVERALL_PICK | TEAM_ID | TEAM_CITY | TEAM_NAME | TEAM_ABBREVIATION | ORGANIZATION | ORGANIZATION_TYPE | HEIGHT | WEIGHT | POSITION | JERSEY_NUMBER | BIRTHDATE | AGE |
4 | |-------------|---------------|----------|----------------|--------------|----------------|-----------|-------------|-------------|---------------------|----------------|---------------------|----------|----------|------------|-----------------|-------------|-------|
--------------------------------------------------------------------------------
/src/nba_api/stats/library/eventmsgtype.py:
--------------------------------------------------------------------------------
1 | from nba_api.library._enum_base import DeprecatedEnum
2 |
3 |
4 | class EventMsgType(DeprecatedEnum):
5 | FIELD_GOAL_MADE = 1
6 | FIELD_GOAL_MISSED = 2
7 | FREE_THROW = 3
8 | REBOUND = 4
9 | TURNOVER = 5
10 | FOUL = 6
11 | VIOLATION = 7
12 | SUBSTITUTION = 8
13 | TIMEOUT = 9
14 | JUMP_BALL = 10
15 | EJECTION = 11
16 | PERIOD_BEGIN = 12
17 | PERIOD_END = 13
18 | # Deprecated as of 2023.11.10
19 | UNKNOWN = 18, "'UNKNOWN' member is deprecated; use 'INSTANT_REPLAY' instead."
20 | INSTANT_REPLAY = 18
21 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/assistleaders_output.md:
--------------------------------------------------------------------------------
1 | AssistLeaders:
2 |
3 | | RANK | TEAM_ID | TEAM_ABBREVIATION | TEAM_NAME | AST |
4 | |-------:|-----------:|:--------------------|:----------------------|------:|
5 | | 1 | 1610612754 | IND | Indiana Pacers | 2522 |
6 | | 2 | 1610612759 | SAS | San Antonio Spurs | 2449 |
7 | | 3 | 1610612743 | DEN | Denver Nuggets | 2415 |
8 | | 4 | 1610612744 | GSW | Golden State Warriors | 2402 |
9 | | 5 | 1610612747 | LAL | Los Angeles Lakers | 2340 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "editor.formatOnSave": true,
3 | "flake8.args": [
4 | "--config=.flake8"
5 | ],
6 | "python.formatting.provider": "black",
7 | "python.formatting.blackArgs": [
8 | "--line-length",
9 | "88"
10 | ],
11 | "python.analysis.diagnosticSeverityOverrides": {
12 | "reportUnboundVariable": "information",
13 | "reportImplicitStringConcatenation": "warning",
14 | "reportUntypedFunctionDecorator": "information",
15 | },
16 | "python.testing.pytestArgs": [
17 | "tests"
18 | ],
19 | "python.testing.unittestEnabled": false,
20 | "python.testing.pytestEnabled": true
21 | }
--------------------------------------------------------------------------------
/docs/nba_api/tools/stats/endpoint_py_file_generator/generator.md:
--------------------------------------------------------------------------------
1 | # generator.py
2 | >/tools/endpoint_py_file_generator/generator.py
3 |
4 | ## Objects
5 |
6 | ### `get_endpoint_contents`(_`endpoint`_, _`endpoint_analysis`_)
7 |
8 | returns _`file_contents`_
9 |
10 | This function will return the contents of the .py file for that specific endpoint.
11 |
12 | ### `generate_endpoint_file`(_`endpoint`_, _`file_contents`_)
13 |
14 | This function will create the .py file for the endpoint and file contents inputted.
15 |
16 | ### `generate_endpoint_files` ( \[_`endpoints_information=load_endpoint_file()`_\] )
17 |
18 | This function will create all the .py files from the endpoints information file.
19 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/cumestatsteamgames_output.md:
--------------------------------------------------------------------------------
1 | CumeStatsTeamGames:
2 |
3 | | MATCHUP | GAME_ID |
4 | |:---------------------------------|-----------:|
5 | | 04/14/2024 Mavericks at Thunder | 0022301196 |
6 | | 04/12/2024 Pistons at Mavericks | 0022301181 |
7 | | 04/10/2024 Mavericks at Heat | 0022301161 |
8 | | 04/09/2024 Mavericks at Hornets | 0022301144 |
9 | | 04/07/2024 Rockets at Mavericks | 0022301131 |
10 | | 04/05/2024 Warriors at Mavericks | 0022301097 |
11 | | 04/04/2024 Hawks at Mavericks | 0022301124 |
12 | | 04/02/2024 Mavericks at Warriors | 0022300589 |
13 | | 03/31/2024 Mavericks at Rockets | 0022301083 |
14 | | 03/29/2024 Mavericks at Kings | 0022301073 |
--------------------------------------------------------------------------------
/src/nba_api/live/nba/endpoints/_base.py:
--------------------------------------------------------------------------------
1 | import json
2 |
3 |
4 | class Endpoint:
5 | class DataSet:
6 | key = None
7 | data = {}
8 |
9 | def __init__(self, data={}):
10 | self.data = data
11 |
12 | def get_json(self):
13 | return json.dumps(self.data)
14 |
15 | def get_dict(self):
16 | return self.data
17 |
18 | def get_request_url(self):
19 | return self.nba_response.get_url()
20 |
21 | def get_response(self):
22 | return self.nba_response.get_response()
23 |
24 | def get_dict(self):
25 | return self.nba_response.get_dict()
26 |
27 | def get_json(self):
28 | return self.nba_response.get_json()
29 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/cumestatsplayergames_output.md:
--------------------------------------------------------------------------------
1 | CumeStatsPlayerGames:
2 |
3 | | MATCHUP | GAME_ID |
4 | |:---------------------------------|-----------:|
5 | | 04/10/2024 Mavericks at Heat | 0022301161 |
6 | | 04/09/2024 Mavericks at Hornets | 0022301144 |
7 | | 04/07/2024 Rockets at Mavericks | 0022301131 |
8 | | 04/04/2024 Hawks at Mavericks | 0022301124 |
9 | | 04/02/2024 Mavericks at Warriors | 0022300589 |
10 | | 03/31/2024 Mavericks at Rockets | 0022301083 |
11 | | 03/29/2024 Mavericks at Kings | 0022301073 |
12 | | 03/26/2024 Mavericks at Kings | 0022301047 |
13 | | 03/25/2024 Mavericks at Jazz | 0022301041 |
14 | | 03/21/2024 Jazz at Mavericks | 0022301008 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/franchiseleaders_output.md:
--------------------------------------------------------------------------------
1 | FranchiseLeaders:
2 |
3 | | TEAM_ID | PTS | PTS_PERSON_ID | PTS_PLAYER | AST | AST_PERSON_ID | AST_PLAYER | REB | REB_PERSON_ID | REB_PLAYER | BLK | BLK_PERSON_ID | BLK_PLAYER | STL | STL_PERSON_ID | STL_PLAYER |
4 | |-----------:|------:|----------------:|:--------------|------:|----------------:|:-------------|------:|----------------:|:--------------|------:|----------------:|:--------------|------:|----------------:|:-------------|
5 | | 1610612742 | 31560 | 1717 | Dirk Nowitzki | 5111 | 157 | Derek Harper | 11489 | 1717 | Dirk Nowitzki | 1281 | 1717 | Dirk Nowitzki | 1551 | 157 | Derek Harper |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/teamhistoricalleaders_output.md:
--------------------------------------------------------------------------------
1 | CareerLeadersByTeam:
2 |
3 | | TEAM_ID | PTS | PTS_PERSON_ID | PTS_PLAYER | AST | AST_PERSON_ID | AST_PLAYER | REB | REB_PERSON_ID | REB_PLAYER | BLK | BLK_PERSON_ID | BLK_PLAYER | STL | STL_PERSON_ID | STL_PLAYER | SEASON_YEAR |
4 | |-----------:|------:|----------------:|:--------------|------:|----------------:|:-------------|------:|----------------:|:--------------|------:|----------------:|:--------------|------:|----------------:|:-------------|:--------------|
5 | | 1610612742 | 31560 | 1717 | Dirk Nowitzki | 5111 | 157 | Derek Harper | 11489 | 1717 | Dirk Nowitzki | 1281 | 1717 | Dirk Nowitzki | 1551 | 157 | Derek Harper | 2023-24 |
--------------------------------------------------------------------------------
/tools/library/file_handler.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 |
4 | def load_file(file_path, file_name):
5 | file_path = os.path.join(file_path, file_name)
6 | f = open(file_path, "r")
7 | contents = f.read()
8 | f.close()
9 | return contents
10 |
11 |
12 | def save_file(file_path, file_name, contents):
13 | file_path = os.path.join(file_path, file_name)
14 | f = open(file_path, "w")
15 | f.write(contents)
16 | f.close()
17 |
18 |
19 | def get_file_path(directory_name, file_name=None):
20 | if not os.path.exists(directory_name):
21 | os.makedirs(directory_name)
22 | if file_name:
23 | file_path = os.path.join(os.getcwd(), directory_name, file_name)
24 | else:
25 | file_path = os.path.join(os.getcwd(), directory_name)
26 | return file_path
27 |
--------------------------------------------------------------------------------
/docs/nba_api/tools/stats/endpoint_documentation_generator/generator.md:
--------------------------------------------------------------------------------
1 | # generator.py
2 | >/tools/endpoint_py_file_generator/generator.py
3 |
4 | ## Objects
5 |
6 | ### `get_endpoint_query_string_parameters`(_`parameters`_, _`nullable_parameters`_, _`parameter_patterns`_)
7 |
8 | returns _`valid_url`_
9 |
10 | This function will return the query string for a url based on the parameters, nullable properties, and parameter patterns.
11 |
12 | ### `get_endpoint_documentation`(_`endpoint`_, _`endpoints_information`_)
13 |
14 | returns _`documentation_text`_
15 |
16 | This function will return the entire documentation text based on the endpoint and endpoints information provided.
17 |
18 | ### `generate_all_endpoint_documentation`( \[_`directory='endpoint_documentation'`_\] )
19 |
20 | This function will generate all documentation text based on the endpoints in the endpoint_list.
21 |
--------------------------------------------------------------------------------
/scripts/analyze_endpoints_and_create_files.py:
--------------------------------------------------------------------------------
1 | from tools.stats.endpoint_analysis import analysis as endpoint_analysis
2 | from tools.stats.endpoint_py_file_generator import generator as py_file_generator
3 | from tools.stats.endpoint_documentation_generator import (
4 | generator as endpoint_documentation_generator,
5 | )
6 | from tools.stats.parameter_documentation_generator import (
7 | generator as parameter_documentation_generator,
8 | )
9 |
10 | # Analyze Endpoints
11 |
12 | endpoint_analysis.analyze_all_endpoints_with_threading()
13 | endpoint_analysis.analyze_and_save_all_endpoints(pause=0)
14 |
15 | # Generate Endpoint Py Files
16 |
17 | py_file_generator.generate_endpoint_files()
18 |
19 | # Generate Endpoint Documentation
20 |
21 | endpoint_documentation_generator.generate_all_endpoint_documentation()
22 |
23 | # Generate Parameter Documentation
24 |
25 | parameter_documentation_generator.generate_parameter_documentation_file()
26 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/commonteamyears_output.md:
--------------------------------------------------------------------------------
1 | TeamYears:
2 |
3 | | LEAGUE_ID | TEAM_ID | MIN_YEAR | MAX_YEAR | ABBREVIATION |
4 | |------------:|-----------:|-----------:|-----------:|:---------------|
5 | | 00 | 1610610023 | 1949 | 1949 | |
6 | | 00 | 1610610024 | 1947 | 1954 | |
7 | | 00 | 1610610025 | 1946 | 1949 | |
8 | | 00 | 1610610026 | 1946 | 1946 | |
9 | | 00 | 1610610027 | 1949 | 1949 | |
10 | | 00 | 1610610028 | 1946 | 1946 | |
11 | | 00 | 1610610029 | 1948 | 1948 | |
12 | | 00 | 1610610030 | 1949 | 1952 | |
13 | | 00 | 1610610031 | 1946 | 1946 | |
14 | | 00 | 1610610032 | 1946 | 1948 | |
--------------------------------------------------------------------------------
/docs/package_structure.md:
--------------------------------------------------------------------------------
1 | # Package Structure
2 |
3 |
4 |
5 | # `\analysis_archive`
6 | This directory is the archive of endpoint analysis files.
7 |
8 | # `\docs`
9 | This directory contains the documentation for the package.
10 |
11 | # `\nba_api`
12 | This is the directory that contains the package.
13 |
14 | #### `\stats`
15 | This directory contains all library for stats.nba.com API.
16 |
17 | #### `\library`
18 | This directory contains files that are necessary to the package. In addition, these files can be used for additional purposes such as connecting to an endpoint or valid parameter values for endpoints.
19 |
20 | # `\scripts`
21 | This directory contains the scripts.
22 |
23 | # `\tests`
24 | This directory contains the tests.
25 |
26 | # `\tools`
27 | This directory contains the foundational tools of this package. These tools are used to help keep the package and documentation updated.
--------------------------------------------------------------------------------
/docs/nba_api/stats/library/data.md:
--------------------------------------------------------------------------------
1 | # data.py
2 | >/nba_api/stats/library/data.py
3 |
4 | This module contains static data to be used with that `nba_api/stats/static` directory.
5 |
6 | ### list `players`
7 |
8 | ```text
9 | player_id, last_name, first_name, full_name
10 | ```
11 |
12 | This is a list of lists of player information.
13 |
14 | `player_index_id` = `0`
15 |
16 | `player_index_last_name` = `1`
17 |
18 | `player_index_first_name` = `2`
19 |
20 | `player_index_full_name` = `3`
21 |
22 | `player_index_is_active` = `4`
23 |
24 |
25 |
26 | ### list `teams`
27 |
28 | ```text
29 | team_id = abbreviation, nickname, year_founded, city, full_name, state
30 | ```
31 |
32 | This is a list of lists of team information.
33 |
34 | `team_index_id` = `0`
35 |
36 | `team_index_abbreviation` = `1`
37 |
38 | `team_index_nickname` = `2`
39 |
40 | `team_index_year_founded` = `3`
41 |
42 | `team_index_city` = `4`
43 |
44 | `team_index_full_name` = `5`
45 |
46 | `team_index_state` = `6`
47 |
--------------------------------------------------------------------------------
/tests/unit/test_stats_endpoints_base.py:
--------------------------------------------------------------------------------
1 | import pytest
2 | from pandas import DataFrame
3 | from nba_api.stats.endpoints._base import Endpoint
4 |
5 |
6 | def test_headers_not_present():
7 | data = {"some_key": "some_value"} # No 'headers' key
8 | instance = Endpoint.DataSet(data)
9 | result = instance.get_data_frame()
10 | assert isinstance(result, DataFrame)
11 | assert result.empty
12 |
13 |
14 | def test_headers_empty():
15 | data = {"headers": [], "name": "Test", "rowSet": []} # Empty 'headers' key
16 | instance = Endpoint.DataSet(data)
17 | result = instance.get_data_frame()
18 | assert isinstance(result, DataFrame)
19 | assert result.empty
20 |
21 |
22 | def test_headers_present_and_nonempty():
23 | data = {"headers": ["GAME_ID", "LEAG_TIX"], "data": [], }
24 | instance = Endpoint.DataSet(data)
25 | result = instance.get_data_frame()
26 | assert isinstance(result, DataFrame)
27 | assert result.empty
28 | assert list(result.columns) == ["GAME_ID", "LEAG_TIX"]
29 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/commonplayoffseries_output.md:
--------------------------------------------------------------------------------
1 | PlayoffSeries:
2 |
3 | | GAME_ID | HOME_TEAM_ID | VISITOR_TEAM_ID | SERIES_ID | GAME_NUM |
4 | |-----------:|---------------:|------------------:|------------:|-----------:|
5 | | 0042300101 | 1610612738 | 1610612748 | 004230010 | 1 |
6 | | 0042300102 | 1610612738 | 1610612748 | 004230010 | 2 |
7 | | 0042300103 | 1610612748 | 1610612738 | 004230010 | 3 |
8 | | 0042300104 | 1610612748 | 1610612738 | 004230010 | 4 |
9 | | 0042300105 | 1610612738 | 1610612748 | 004230010 | 5 |
10 | | 0042300111 | 1610612752 | 1610612755 | 004230011 | 1 |
11 | | 0042300112 | 1610612752 | 1610612755 | 004230011 | 2 |
12 | | 0042300113 | 1610612755 | 1610612752 | 004230011 | 3 |
13 | | 0042300114 | 1610612755 | 1610612752 | 004230011 | 4 |
14 | | 0042300115 | 1610612752 | 1610612755 | 004230011 | 5 |
--------------------------------------------------------------------------------
/docs/nba_api/debug.md:
--------------------------------------------------------------------------------
1 | # debug.py
2 | >/nba_api/debug.py
3 |
4 | The purpose of this module is to set the library into debug mode as well as set your proxy and headers.
5 |
6 |
7 | ## `DEBUG`
8 |
9 | `boolean`
10 |
11 | Set this value to `true` in order to enable debug mode.
12 |
13 |
14 | ## `DEBUG_STORAGE`
15 |
16 | `boolean`
17 |
18 | Set this value to `true` in order to enable text file saving of every request. Parameters are joined together and an MD5 hash is used to create the file name in a `debug_storage` folder.
19 |
20 | This feature is primarily used to help debug any issues as well as develop additional features.
21 |
22 | This feature is dependent on `DEBUG` to be `true`. If not, then this feature will not be enabled, regardless of the setting.
23 |
24 |
25 | ## `PROXY`
26 |
27 | `string`
28 |
29 | ```python
30 | PROXY = '127.0.0.1:80'
31 | ```
32 |
33 | Set this value to run requests through a proxy.
34 |
35 | ## `STATS_HEADERS`
36 |
37 | `dictionary`
38 |
39 | Set this value to override the headers of the `stats.nba.com` API Endpoints.
40 |
--------------------------------------------------------------------------------
/tests/integration/data/scoreboardv3.py:
--------------------------------------------------------------------------------
1 | """
2 | Test data for ScoreboardV3 endpoint.
3 |
4 | GitHub Issues:
5 | - #580: Implement ScoreboardV3 endpoint
6 |
7 | Expected response formats:
8 | - String: "success" | "has_data" | "empty" | "error"
9 | - Dict: {"status": "success", "min_rows": 1, "max_rows": 100}
10 | """
11 |
12 | # Endpoint class name
13 | ENDPOINT_CLASS = "ScoreboardV3"
14 |
15 | # Test cases
16 | TEST_CASES = [
17 | {
18 | "description": "Regular season game date - November 5, 2025",
19 | "params": {"game_date": "2025-11-05"},
20 | "expected": "has_data", # Should have games
21 | },
22 | {
23 | "description": "Offseason date - no games expected",
24 | "params": {"game_date": "2025-07-15"},
25 | "expected": "success", # API returns scoreboard info even with no games
26 | },
27 | {
28 | "description": "Custom league ID",
29 | "params": {"game_date": "2025-11-05", "league_id": "00"},
30 | "expected": "has_data", # Should work with explicit league_id
31 | },
32 | ]
33 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Swar Patel
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/nba_api/live/nba/library/http.py:
--------------------------------------------------------------------------------
1 | from nba_api.library import http
2 |
3 |
4 | try:
5 | from nba_api.library.debug.debug import STATS_HEADERS
6 | except ImportError:
7 | STATS_HEADERS = {
8 | "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
9 | "Accept-Encoding": "gzip, deflate, br",
10 | "Accept-Language": "en-US,en;q=0.9",
11 | "Cache-Control": "max-age=0",
12 | "Connection": "keep-alive",
13 | "Host": "cdn.nba.com",
14 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
15 | }
16 |
17 |
18 | class NBALiveHTTP(http.NBAHTTP):
19 | nba_response = http.NBAResponse
20 | base_url = "https://cdn.nba.com/static/json/liveData/{endpoint}"
21 | headers = STATS_HEADERS
22 |
23 | def clean_contents(self, contents):
24 | if '{"Message":"An error has occurred."}' in contents:
25 | return "An error has occurred."
26 | return contents
27 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/playerfantasyprofilebargraph_output.md:
--------------------------------------------------------------------------------
1 | SeasonAvg:
2 |
3 | | PLAYER_ID | PLAYER_NAME | TEAM_ID | TEAM_ABBREVIATION | FAN_DUEL_PTS | NBA_FANTASY_PTS | PTS | REB | AST | FG3M | FT_PCT | STL | BLK | TOV | FG_PCT |
4 | |------------:|:--------------|-----------:|:--------------------|---------------:|------------------:|------:|------:|------:|-------:|---------:|------:|------:|------:|---------:|
5 | | 1629029 | Luka Doncic | 1610612742 | DAL | 59.5 | 61.5 | 33.9 | 9.2 | 9.8 | 4.1 | 0.786 | 1.41 | 0.54 | 4 | 0.487 |
6 |
7 | LastFiveGamesAvg:
8 |
9 | | PLAYER_ID | PLAYER_NAME | TEAM_ID | TEAM_ABBREVIATION | FAN_DUEL_PTS | NBA_FANTASY_PTS | PTS | REB | AST | FG3M | FT_PCT | STL | BLK | TOV | FG_PCT |
10 | |------------:|:--------------|-----------:|:--------------------|---------------:|------------------:|------:|------:|------:|-------:|---------:|------:|------:|------:|---------:|
11 | | 1629029 | Luka Doncic | 1610612742 | DAL | 57.6 | 58.8 | 32 | 10.8 | 10 | 5.4 | 0.871 | 0.4 | 0.8 | 4.8 | 0.457 |
--------------------------------------------------------------------------------
/docs/endpoint_analysis_format.md:
--------------------------------------------------------------------------------
1 | # Endpoint Analysis Format
2 |
3 | ### Endpoint Analysis JSON Format
4 | ```json
5 | {
6 | "{endpoint}": {
7 | "status": "{status}",
8 | "endpoint": "{endpoint}",
9 | "data_sets": {},
10 | "parameters": [],
11 | "required_parameters": [],
12 | "nullable_parameters": [],
13 | "parameters_patterns": {
14 | "{property}": "{pattern}",
15 | }
16 | }
17 | }
18 | ```
19 |
20 | Name | Explanation
21 | ------------ | -------------
22 | _**status**_ | This field will be 'success' or 'fail'. Success statuses have passed all tests required by the endpoint analysis.
23 | _**endpoint**_ | The name of the endpoint.
24 | _**data_sets**_ | The data sets that are returned by the endpoint and their data headers.
25 | _**parameters**_ | All parameters for the endpoint.
26 | _**required_parameters**_ | All parameters for the endpoint that throw a required flag. _Please note, required parameters can also be nullable. They just require a parameter to be passed._
27 | _**nullable_parameters**_ | All parameters for the endpoint that do not require a value.
28 | _**parameter_patterns**_ | Regular expression patterns for each parameter.
29 |
--------------------------------------------------------------------------------
/tools/stats/endpoint_documentation_generator/template.py:
--------------------------------------------------------------------------------
1 | endpoint_documentation_template = """# {endpoint}
2 | ##### [nba_api/stats/endpoints/{endpoint__lowercase}.py](https://github.com/swar/nba_api/blob/master/src/nba_api/stats/endpoints/{endpoint__lowercase}.py)
3 |
4 | ##### Endpoint URL
5 | >[https://stats.nba.com/stats/{endpoint__lowercase}](https://stats.nba.com/stats/{endpoint__lowercase})
6 |
7 | ##### Valid URL
8 | >[https://stats.nba.com/stats/{endpoint__lowercase}?{query_string_parameters}](https://stats.nba.com/stats/{endpoint__lowercase}?{query_string_parameters})
9 |
10 | ## Parameters
11 | API Parameter Name | Python Parameter Variable | Pattern | Required | Nullable
12 | ------------ | ------------ | :-----------: | :---: | :---:
13 | {parameters}
14 |
15 | ## Data Sets
16 | {data_sets}
17 |
18 | ## JSON
19 | ```json
20 | {json}
21 | ```
22 |
23 | Last validated {validated_date}"""
24 |
25 | data_set_template = """#### {data_set_name} `{method_name}`
26 | ```text
27 | {columns}
28 | ```
29 | """
30 |
31 | parameter_line_template = """[_**{api_parameter_name}**_](https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md#{api_parameter_name}) | {python_parameter_variable} | {pattern} | {required} | {nullable} | """
32 |
--------------------------------------------------------------------------------
/.flake8:
--------------------------------------------------------------------------------
1 | [flake8]
2 | min_python_version = 3.7.0
3 |
4 | # 'NBAHTTP.send_api_request' is too complex (15)
5 | max-complexity = 15
6 |
7 | # Multiple Lines are over 88 (extend-ignore includes E501)
8 | max-line-length = 88
9 |
10 | exclude =
11 | .venv
12 | .git
13 | __pycache__
14 | # TODO: Fix Violations
15 | tools
16 | scripts
17 |
18 | extend-ignore =
19 | # TODO: Fix Violations
20 | # indentation is not a multiple of 4
21 | E111
22 | # unexpected spaces around keyword / parameter equals
23 | E251
24 | # at least two spaces before inline comment
25 | E261
26 | # block comment should start with '# '
27 | E265
28 | # expected 2 blank lines, found {n}
29 | E302
30 | # line too long ({chars} > {max-line-length} characters)
31 | E501
32 | # comparison to False should be 'if cond is False:' or 'if not cond:'
33 | E712
34 | # imported but unused
35 | F401
36 | # unable to detect undefined names
37 | F403
38 | # may be undefined, or defined from star imports:
39 | F405
40 | # trailing whitespace
41 | W291
42 | # no newline at end of file
43 | W292
44 | # blank line contains whitespace
45 | W293
46 | # blank line at end of file
47 | W391
48 |
--------------------------------------------------------------------------------
/tests/integration/data/playerdashptshotdefend.py:
--------------------------------------------------------------------------------
1 | """
2 | Test data for PlayerDashPtShotDefend endpoint.
3 |
4 | GitHub Issues:
5 | - User reports: "team_id requirement needs to be taken off"
6 | - User reports: "returns empty for certain seasons"
7 |
8 | Expected response formats:
9 | - String: "success" | "has_data" | "empty" | "error"
10 | - Dict: {"status": "success", "min_rows": 1, "max_rows": 100}
11 | """
12 |
13 | # Endpoint class name
14 | ENDPOINT_CLASS = "PlayerDashPtShotDefend"
15 |
16 | # Test cases
17 | TEST_CASES = [
18 | {
19 | "description": "Basic test - LeBron 2023-24 Lakers",
20 | "params": {"player_id": "2544", "team_id": 1610612747, "season": "2023-24"},
21 | "expected": "success", # Endpoint should work
22 | },
23 | {
24 | "description": "Team ID zero - all teams",
25 | "params": {"player_id": "2544", "team_id": 0, "season": "2023-24"},
26 | "expected": "has_data", # Returns data for all teams
27 | },
28 | {
29 | "description": "Playoffs 2023-24",
30 | "params": {
31 | "player_id": "2544",
32 | "team_id": 1610612747,
33 | "season": "2023-24",
34 | "season_type_all_star": "Playoffs",
35 | },
36 | "expected": "success",
37 | },
38 | ]
39 |
--------------------------------------------------------------------------------
/.devcontainer/post-create-command.sh:
--------------------------------------------------------------------------------
1 | pip install --upgrade pip
2 | poetry install
3 | # Activate poetry environment
4 | source $(poetry env info --path)/bin/activate
5 |
6 | # Update PYTHONPATH to include the virtual environment's Python interpreter
7 | echo "export PYTHON_PATH=$(poetry env info --path)/bin/python" >> ~/.bashrc
8 | #!/bin/bash
9 | # Shebang: tells the system to execute this script using bash
10 |
11 | # Exit immediately if any command fails (prevents partial setup)
12 | # This ensures the development environment is either fully set up or fails clearly
13 | set -e
14 |
15 | # Display status message to user during container setup
16 | echo "Setting up development environment..."
17 |
18 | # Install all dependencies from pyproject.toml and poetry.lock
19 | # --with linting,test includes optional dependency groups for development tools
20 | # This creates the .venv directory and installs packages inside it
21 | poetry install
22 |
23 | # Configure shell activation for all future terminal sessions
24 | # This adds a command to .bashrc that automatically activates the Poetry environment
25 | # The '2>/dev/null || true' suppresses errors if Poetry environment doesn't exist yet
26 | echo 'eval "$(poetry env activate)" 2>/dev/null || true' >> ~/.bashrc
27 |
28 | # Display completion message to user
29 | echo "Setup complete! Poetry environment activated."
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_data_structure.md:
--------------------------------------------------------------------------------
1 | # class `Endpoint`
2 |
3 | ## `get_request_url`( )
4 |
5 | Returns the url of the request.
6 |
7 | ## `get_available_data`( )
8 |
9 | Returns the data set names that are in the object.
10 |
11 | ## `get_response`( )
12 |
13 | Returns the raw `string` response.
14 |
15 | ## `get_dict`( )
16 |
17 | Returns the response in a `dictionary`.
18 |
19 | ## `get_json`( )
20 |
21 | Returns the response in a `json`.
22 |
23 | ## `get_normalized_dict`( )
24 |
25 | Returns the response in a normalized `dictionary`.
26 |
27 | ## `get_normalized_json`( )
28 |
29 | Returns the response in a normalized `json`.
30 |
31 | ## `get_data_frames`( )
32 |
33 | Returns the a `list` of data sets in `DataFrame` objects.
34 |
35 | ## class `DataSet`
36 |
37 | #### `__init__`(_`data`_)
38 | ```python
39 | data = data_set
40 | ```
41 | ```python
42 | data_set = {'name': name, 'headers': headers, 'data': data}
43 | ```
44 |
45 | #### `get_json`( )
46 | returns the data set in a `json` object.
47 | ```json
48 | {"name": name, "headers": [headers...], "data": [[data1], [data2], ...]}
49 | ```
50 |
51 | #### `get_dict`( )
52 | returns the data set in a `dictionary` object.
53 | ```python
54 | data_set = {'name': name, 'headers': [headers...], 'data': [[data1], [data2], ...]}
55 | ```
56 |
57 | #### `get_data_frame`( )
58 | returns the data set in a `DataFrame` object. If `pandas` fails to import, this method will raise an exception.
59 |
60 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/shotchartleaguewide_output.md:
--------------------------------------------------------------------------------
1 | League_Wide:
2 |
3 | | GRID_TYPE | SHOT_ZONE_BASIC | SHOT_ZONE_AREA | SHOT_ZONE_RANGE | FGA | FGM | FG_PCT |
4 | |:----------------|:----------------------|:----------------------|:------------------|------:|------:|---------:|
5 | | League Averages | Above the Break 3 | Back Court(BC) | Back Court Shot | 34 | 3 | 0.088 |
6 | | League Averages | Above the Break 3 | Center(C) | 24+ ft. | 16718 | 5989 | 0.358 |
7 | | League Averages | Above the Break 3 | Left Side Center(LC) | 24+ ft. | 26343 | 9426 | 0.358 |
8 | | League Averages | Above the Break 3 | Right Side Center(RC) | 24+ ft. | 24458 | 8862 | 0.362 |
9 | | League Averages | Backcourt | Back Court(BC) | Back Court Shot | 477 | 10 | 0.021 |
10 | | League Averages | In The Paint (Non-RA) | Center(C) | 8-16 ft. | 13253 | 6041 | 0.456 |
11 | | League Averages | In The Paint (Non-RA) | Center(C) | Less Than 8 ft. | 27251 | 11803 | 0.433 |
12 | | League Averages | In The Paint (Non-RA) | Left Side(L) | 8-16 ft. | 2415 | 1076 | 0.446 |
13 | | League Averages | In The Paint (Non-RA) | Right Side(R) | 8-16 ft. | 2729 | 1179 | 0.432 |
14 | | League Averages | Left Corner 3 | Left Side(L) | 24+ ft. | 12210 | 4690 | 0.384 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/videoevents.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 |
4 |
5 | class VideoEvents(Endpoint):
6 | endpoint = "videoevents"
7 | expected_data = {}
8 |
9 | nba_response = None
10 | data_sets = None
11 | player_stats = None
12 | team_stats = None
13 | headers = None
14 |
15 | def __init__(
16 | self,
17 | game_id,
18 | game_event_id=0,
19 | proxy=None,
20 | headers=None,
21 | timeout=30,
22 | get_request=True,
23 | ):
24 | self.proxy = proxy
25 | if headers is not None:
26 | self.headers = headers
27 | self.timeout = timeout
28 | self.parameters = {"GameID": game_id, "GameEventID": game_event_id}
29 | if get_request:
30 | self.get_request()
31 |
32 | def get_request(self):
33 | self.nba_response = NBAStatsHTTP().send_api_request(
34 | endpoint=self.endpoint,
35 | parameters=self.parameters,
36 | proxy=self.proxy,
37 | headers=self.headers,
38 | timeout=self.timeout,
39 | )
40 | self.load_response()
41 |
42 | def load_response(self):
43 | data_sets = self.nba_response.get_data_sets()
44 | self.data_sets = [
45 | Endpoint.DataSet(data=data_set)
46 | for data_set_name, data_set in data_sets.items()
47 | ]
48 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/teaminfocommon_output.md:
--------------------------------------------------------------------------------
1 | TeamInfoCommon:
2 |
3 | | TEAM_ID | SEASON_YEAR | TEAM_CITY | TEAM_NAME | TEAM_ABBREVIATION | TEAM_CONFERENCE | TEAM_DIVISION | TEAM_CODE | TEAM_SLUG | W | L | PCT | CONF_RANK | DIV_RANK | MIN_YEAR | MAX_YEAR |
4 | |-----------:|:--------------|:------------|:------------|:--------------------|:------------------|:----------------|:------------|:------------|----:|----:|------:|------------:|-----------:|-----------:|-----------:|
5 | | 1610612742 | 2023-24 | Dallas | Mavericks | DAL | West | Southwest | mavericks | mavericks | 50 | 32 | 0.61 | 5 | 1 | 1980 | 2023 |
6 |
7 | TeamSeasonRanks:
8 |
9 | | LEAGUE_ID | SEASON_ID | TEAM_ID | PTS_RANK | PTS_PG | REB_RANK | REB_PG | AST_RANK | AST_PG | OPP_PTS_RANK | OPP_PTS_PG |
10 | |------------:|------------:|-----------:|-----------:|---------:|-----------:|---------:|-----------:|---------:|---------------:|-------------:|
11 | | 00 | 22023 | 1610612742 | 7 | 117.9 | 21 | 42.9 | 19 | 25.7 | 20 | 115.6 |
12 |
13 | AvailableSeasons:
14 |
15 | | SEASON_ID |
16 | |------------:|
17 | | 21980 |
18 | | 21981 |
19 | | 21982 |
20 | | 21983 |
21 | | 41983 |
22 | | 21984 |
23 | | 41984 |
24 | | 21985 |
25 | | 41985 |
26 | | 21986 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/videoeventsasset.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 |
4 |
5 | class VideoEventsAsset(Endpoint):
6 | endpoint = "videoeventsasset"
7 | expected_data = {}
8 |
9 | nba_response = None
10 | data_sets = None
11 | player_stats = None
12 | team_stats = None
13 | headers = None
14 |
15 | def __init__(
16 | self,
17 | game_id,
18 | game_event_id=0,
19 | proxy=None,
20 | headers=None,
21 | timeout=30,
22 | get_request=True,
23 | ):
24 | self.proxy = proxy
25 | if headers is not None:
26 | self.headers = headers
27 | self.timeout = timeout
28 | self.parameters = {"GameID": game_id, "GameEventID": game_event_id}
29 | if get_request:
30 | self.get_request()
31 |
32 | def get_request(self):
33 | self.nba_response = NBAStatsHTTP().send_api_request(
34 | endpoint=self.endpoint,
35 | parameters=self.parameters,
36 | proxy=self.proxy,
37 | headers=self.headers,
38 | timeout=self.timeout,
39 | )
40 | self.load_response()
41 |
42 | def load_response(self):
43 | data_sets = self.nba_response.get_data_sets()
44 | self.data_sets = [
45 | Endpoint.DataSet(data=data_set)
46 | for data_set_name, data_set in data_sets.items()
47 | ]
48 |
--------------------------------------------------------------------------------
/src/nba_api/library/_enum_base.py:
--------------------------------------------------------------------------------
1 | from enum import Enum, EnumMeta
2 |
3 |
4 | class OnAccess(EnumMeta):
5 | """
6 | runs a user-specified function whenever member is accessed
7 | """
8 |
9 | def __getattribute__(cls, name):
10 | obj = super().__getattribute__(name)
11 | if isinstance(obj, Enum) and obj._on_access:
12 | obj._on_access()
13 | return obj
14 |
15 | def __getitem__(cls, name):
16 | member = super().__getitem__(name)
17 | if member._on_access:
18 | member._on_access()
19 | return member
20 |
21 | def __call__(
22 | cls, value, names=None, *, module=None, qualname=None, type=None, start=1
23 | ):
24 | obj = super().__call__(
25 | value, names, module=module, qualname=qualname, type=type, start=start
26 | )
27 | if isinstance(obj, Enum) and obj._on_access:
28 | obj._on_access()
29 | return obj
30 |
31 |
32 | class DeprecatedEnum(Enum, metaclass=OnAccess):
33 | def __new__(cls, value, *args):
34 | member = object.__new__(cls)
35 | member._value_ = value
36 | member._args = args
37 | member._on_access = member.deprecate if args else None
38 | return member
39 |
40 | def deprecate(self):
41 | args = self._args
42 | import warnings
43 |
44 | warnings.warn(
45 | "%s" % args,
46 | DeprecationWarning,
47 | stacklevel=3,
48 | )
49 |
--------------------------------------------------------------------------------
/src/nba_api/stats/library/parserv3.py:
--------------------------------------------------------------------------------
1 | """
2 | DEPRECATED: This module has been moved to nba_api.stats.endpoints._parsers
3 |
4 | The parsers have been split into individual files for better organization:
5 | - boxscoreadvancedv3.py
6 | - boxscoretraditionalv3.py
7 | - boxscorematchupsv3.py
8 | - boxscoresummaryv3.py
9 | - playbyplayv3.py
10 | - iststandings.py
11 | - scheduleleaguev2.py
12 |
13 | Please update your imports:
14 | OLD: from nba_api.stats.library.parserv3 import NBAStatsBoxscoreParserV3
15 | NEW: from nba_api.stats.endpoints._parsers import NBAStatsBoxscoreParserV3
16 |
17 | Note: _parsers is private/internal. Do not import directly unless necessary.
18 |
19 | This module will be removed in a future version.
20 | """
21 |
22 | import warnings
23 |
24 | # Re-export from new location for backward compatibility
25 | from nba_api.stats.endpoints._parsers import ( # noqa: F401
26 | NBAStatsBoxscoreAdvancedV3Parser,
27 | NBAStatsBoxscoreMatchupsParserV3,
28 | NBAStatsBoxscoreSummaryParserV3,
29 | NBAStatsBoxscoreTraditionalParserV3,
30 | NBAStatsISTStandingsParser,
31 | NBAStatsPlayByPlayParserV3,
32 | NBAStatsScheduleLeagueV2IntParser,
33 | NBAStatsScheduleLeagueV2Parser,
34 | get_parser_for_endpoint,
35 | )
36 |
37 | # Legacy alias for backward compatibility
38 | NBAStatsBoxscoreParserV3 = NBAStatsBoxscoreAdvancedV3Parser
39 |
40 | warnings.warn(
41 | "nba_api.stats.library.parserv3 is deprecated. "
42 | "Use nba_api.stats.endpoints._parsers instead (internal API).",
43 | DeprecationWarning,
44 | stacklevel=2,
45 | )
46 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/homepageleaders_output.md:
--------------------------------------------------------------------------------
1 | HomePageLeaders:
2 |
3 | | RANK | TEAM_ID | TEAM_NAME | TEAM_ABBREVIATION | PTS | FG_PCT | FG3_PCT | FT_PCT | EFG_PCT | TS_PCT | PTS_PER48 |
4 | |-------:|-----------:|:----------------------|:--------------------|------:|---------:|----------:|---------:|----------:|---------:|------------:|
5 | | 1 | 1610612754 | Indiana Pacers | IND | 123.3 | 0.507 | 0.374 | 0.782 | 0.578 | 0.606 | 123.1 |
6 | | 2 | 1610612738 | Boston Celtics | BOS | 120.6 | 0.487 | 0.388 | 0.807 | 0.578 | 0.609 | 119.7 |
7 | | 3 | 1610612760 | Oklahoma City Thunder | OKC | 120.1 | 0.499 | 0.389 | 0.825 | 0.573 | 0.608 | 119.3 |
8 | | 4 | 1610612749 | Milwaukee Bucks | MIL | 119 | 0.487 | 0.373 | 0.774 | 0.568 | 0.601 | 118.2 |
9 | | 5 | 1610612737 | Atlanta Hawks | ATL | 118.3 | 0.465 | 0.364 | 0.797 | 0.539 | 0.576 | 117.3 |
10 |
11 | LeagueAverage:
12 |
13 | | PTS | FG_PCT | FG3_PCT | FT_PCT | EFG_PCT | TS_PCT | PTS_PER48 |
14 | |------:|---------:|----------:|---------:|----------:|---------:|------------:|
15 | | 114.2 | 0.474 | 0.366 | 0.784 | 0.547 | 0.58 | 113.6 |
16 |
17 | LeagueMax:
18 |
19 | | PTS | FG_PCT | FG3_PCT | FT_PCT | EFG_PCT | TS_PCT | PTS_PER48 |
20 | |------:|---------:|----------:|---------:|----------:|---------:|------------:|
21 | | 123.3 | 0.507 | 0.389 | 0.83 | 0.578 | 0.609 | 123.1 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/commonteamyears.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import LeagueID
4 |
5 |
6 | class CommonTeamYears(Endpoint):
7 | endpoint = "commonteamyears"
8 | expected_data = {
9 | "TeamYears": ["LEAGUE_ID", "TEAM_ID", "MIN_YEAR", "MAX_YEAR", "ABBREVIATION"]
10 | }
11 |
12 | nba_response = None
13 | data_sets = None
14 | player_stats = None
15 | team_stats = None
16 | headers = None
17 |
18 | def __init__(
19 | self,
20 | league_id=LeagueID.default,
21 | proxy=None,
22 | headers=None,
23 | timeout=30,
24 | get_request=True,
25 | ):
26 | self.proxy = proxy
27 | if headers is not None:
28 | self.headers = headers
29 | self.timeout = timeout
30 | self.parameters = {"LeagueID": league_id}
31 | if get_request:
32 | self.get_request()
33 |
34 | def get_request(self):
35 | self.nba_response = NBAStatsHTTP().send_api_request(
36 | endpoint=self.endpoint,
37 | parameters=self.parameters,
38 | proxy=self.proxy,
39 | headers=self.headers,
40 | timeout=self.timeout,
41 | )
42 | self.load_response()
43 |
44 | def load_response(self):
45 | data_sets = self.nba_response.get_data_sets()
46 | self.data_sets = [
47 | Endpoint.DataSet(data=data_set)
48 | for data_set_name, data_set in data_sets.items()
49 | ]
50 | self.team_years = Endpoint.DataSet(data=data_sets["TeamYears"])
51 |
--------------------------------------------------------------------------------
/tests/integration/test_stats_endpoints_responses_valid.py:
--------------------------------------------------------------------------------
1 | import time
2 | import json
3 | import random
4 | import pytest
5 |
6 | from deferred_endpoints import deferred_endpoints, DeferredEndpoint
7 |
8 | # Once we run the test to call the endpoints, we'll cache the responses here.
9 | cached_eps = []
10 |
11 |
12 | # This method is passed to test_endpoints so console output will be generated with
13 | # the class name rather than path::test_name[deferred_endpoint12]`
14 | def endpoint_id_func(param):
15 | if isinstance(param, DeferredEndpoint):
16 | return param.endpoint_class.__name__
17 | return None
18 |
19 |
20 | # Run this test on each endpoint in deferred_endpoints.
21 | @pytest.mark.parametrize("deferred_endpoint", deferred_endpoints, ids=endpoint_id_func)
22 | def test_endpoints(deferred_endpoint):
23 | """Test that each endpoint is callable.
24 |
25 | This takes a very, very long time in total (10-20 minutes) because we don't
26 | want to barrage the NBA site with requests."""
27 | # Delay briefly
28 | time.sleep(0.600)
29 | # Call the API.
30 | try:
31 | response = deferred_endpoint()
32 | except json.decoder.JSONDecodeError:
33 | endpoint_class = deferred_endpoint.endpoint_class
34 | msg = "Unable to decode response for {}".format(endpoint_class)
35 | pytest.fail(msg=msg)
36 | # We want to hang onto all the responses so we don't need to re-retrieve
37 | # them later.
38 | cached_eps.append(response)
39 |
40 |
41 | def test_valid_json():
42 | # Check that every called endpoint is valid json.
43 | valid = [ep.nba_response.valid_json() for ep in cached_eps]
44 | assert len(valid) == len(deferred_endpoints)
45 | assert all(valid)
46 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/leaderstiles_output.md:
--------------------------------------------------------------------------------
1 | LeadersTiles:
2 |
3 | | RANK | TEAM_ID | TEAM_ABBREVIATION | TEAM_NAME | PTS |
4 | |-------:|-----------:|:--------------------|:----------------------|------:|
5 | | 1 | 1610612754 | IND | Indiana Pacers | 123.3 |
6 | | 2 | 1610612738 | BOS | Boston Celtics | 120.6 |
7 | | 3 | 1610612760 | OKC | Oklahoma City Thunder | 120.1 |
8 | | 4 | 1610612749 | MIL | Milwaukee Bucks | 119 |
9 | | 5 | 1610612737 | ATL | Atlanta Hawks | 118.3 |
10 |
11 | AllTimeSeasonHigh:
12 |
13 | | TEAM_ID | TEAM_ABBREVIATION | TEAM_NAME | SEASON_YEAR | PTS |
14 | |-----------:|:--------------------|:------------|:--------------|--------:|
15 | | 1610612743 | DEN | Nuggets | 1981-82 | 126.475 |
16 |
17 | LastSeasonHigh:
18 |
19 | | RANK | TEAM_ID | TEAM_ABBREVIATION | TEAM_NAME | PTS |
20 | |-------:|-----------:|:--------------------|:----------------------|------:|
21 | | 1 | 1610612758 | SAC | Sacramento Kings | 120.7 |
22 | | 2 | 1610612744 | GSW | Golden State Warriors | 118.9 |
23 | | 3 | 1610612737 | ATL | Atlanta Hawks | 118.4 |
24 | | 4 | 1610612738 | BOS | Boston Celtics | 117.9 |
25 | | 5 | 1610612760 | OKC | Oklahoma City Thunder | 117.5 |
26 |
27 | LowSeasonHigh:
28 |
29 | | TEAM_ID | TEAM_ABBREVIATION | TEAM_NAME | SEASON_YEAR | PTS |
30 | |-----------:|:--------------------|:------------|:--------------|-------:|
31 | | 1610610025 | CHS | Stags | 1947-48 | 75.833 |
--------------------------------------------------------------------------------
/docs/nba_api/tools/stats/input_output_definitions.md:
--------------------------------------------------------------------------------
1 | # Input / Output Definitions
2 |
3 | ### `nba_stats_response`
4 | [`NBAStatsResponse`]() class
5 |
6 | ### `endpoint`
7 | ```python
8 | endpoint = 'endpoint'
9 | ```
10 |
11 | ### `endpoints`
12 | ```python
13 | endpoints = ['endpoint1', 'endpoint2', ...]
14 | ```
15 |
16 | ### `endpoint_analysis`
17 | ```python
18 | endpoint_analysis = {
19 | 'status': status,
20 | 'endpoint': endpoint,
21 | 'parameters': all_parameters,
22 | 'required_parameters': required_parameters,
23 | 'nullable_parameters': nullable_parameters,
24 | 'parameter_patterns': parameter_patterns,
25 | 'data_sets': data_sets,
26 | }
27 | ```
28 |
29 | ### `endpoints_information`
30 | ```python
31 | endpoints_information = {'endpoint1': endpoint_analysis, ...}
32 | ```
33 |
34 | ### `params`, `required_params`, `params_errors`, `required_params_errors`
35 | ```python
36 | params = {'endpoint': 'error_value', ...}
37 | ```
38 |
39 | ### `parameter_patterns`
40 | ```python
41 | parameter_patterns = {'endpoint': 'pattern', ...}
42 | ```
43 |
44 | ### `status`
45 | status can be either `success`, `invalid`, or `deprecated`
46 |
47 | `success` Endpoint has passed all tests.
48 |
49 | `invalid` Endpoint has not passed all tests.
50 |
51 | `deprecated` Endpoint returns a 404 error page.
52 |
53 | ```python
54 | status = 'status'
55 | ```
56 |
57 | ### `all_parameters`
58 | ```python
59 | all_parameters = ['parameter1', 'parameter2', ...]
60 | ```
61 |
62 | ### `required_parameters`
63 | ```python
64 | required_parameters = ['parameter1', 'parameter2', ...]
65 | ```
66 |
67 | ### `nullable_parameters`
68 | ```python
69 | nullable_parameters = ['parameter1', 'parameter2', ...]
70 | ```
71 |
72 | ### `data_sets`
73 | The data sets returned by the [`NBAStatsResponse`]() class.
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/_parsers/iststandings.py:
--------------------------------------------------------------------------------
1 | """Parser(s) for iststandings endpoint."""
2 |
3 |
4 | class NBAStatsISTStandingsParser:
5 | def __init__(self, nba_dict):
6 | self.nba_dict = nba_dict
7 |
8 | def get_iststandings_headers(self):
9 | team_header = [
10 | key for key, value in self.nba_dict["teams"][0].items() if key != "games"
11 | ]
12 | game_header = []
13 | for game in self.nba_dict["teams"][0]["games"]:
14 | number = game["gameNumber"]
15 | for key, value in game.items():
16 | if key == "gameNumber":
17 | continue
18 | header = key + str(number)
19 | game_header.append(header)
20 | return ["leagueId"] + ["seasonYear"] + team_header + game_header
21 |
22 | def get_iststandings_data(self):
23 | teams_data = []
24 | for team in self.nba_dict["teams"]:
25 | team_value = []
26 | t_data = [value for key, value in team.items() if key != "games"]
27 | team_value.extend([self.nba_dict["leagueId"], self.nba_dict["seasonYear"]])
28 | team_value.extend(t_data)
29 | for game in team["games"]:
30 | for key, value in game.items():
31 | if key == "gameNumber":
32 | continue
33 | team_value.append(value)
34 | teams_data.append(team_value)
35 | return teams_data
36 |
37 | def get_data_sets(self):
38 | results = {"Standings": None}
39 | iststandings_head = self.get_iststandings_headers()
40 | iststandings_data = self.get_iststandings_data()
41 | results["Standings"] = {"headers": iststandings_head, "data": iststandings_data}
42 | return results
43 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints/videoevents.md:
--------------------------------------------------------------------------------
1 | # VideoEvents
2 | ##### [nba_api/stats/endpoints/videoevents.py](https://github.com/swar/nba_api/blob/master/src/nba_api/stats/endpoints/videoevents.py)
3 |
4 | ##### Endpoint URL
5 | >[https://stats.nba.com/stats/videoevents](https://stats.nba.com/stats/videoevents)
6 |
7 | ##### Valid URL
8 | >[https://stats.nba.com/stats/videoevents?GameEventID=0&GameID=0021700807](https://stats.nba.com/stats/videoevents?GameEventID=0&GameID=0021700807)
9 |
10 | ## Parameters
11 | | API Parameter Name | Python Parameter Variable | Pattern | Required | Nullable |
12 | |-----------------------------------------------------------------------------------------------------------------------|---------------------------|:-------------:|:--------:|:--------:|
13 | | [_**GameEventID**_](https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md#GameEventID) | game_event_id | | `Y` | |
14 | | [_**GameID**_](https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md#GameID) | game_id | `^(\d{10})?$` | `Y` | |
15 |
16 | ## Data Sets
17 |
18 |
19 | ## JSON
20 | ```json
21 | {
22 | "data_sets": {},
23 | "endpoint": "VideoEvents",
24 | "last_validated_date": "2020-08-15",
25 | "nullable_parameters": [],
26 | "parameter_patterns": {
27 | "GameEventID": null,
28 | "GameID": "^(\\d{10})?$"
29 | },
30 | "parameters": [
31 | "GameEventID",
32 | "GameID"
33 | ],
34 | "required_parameters": [
35 | "GameEventID",
36 | "GameID"
37 | ],
38 | "status": "success"
39 | }
40 | ```
41 |
42 | Last validated 2020-08-16
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints/commonteamyears.md:
--------------------------------------------------------------------------------
1 | # CommonTeamYears
2 | ##### [nba_api/stats/endpoints/commonteamyears.py](https://github.com/swar/nba_api/blob/master/src/nba_api/stats/endpoints/commonteamyears.py)
3 |
4 | ##### Endpoint URL
5 | >[https://stats.nba.com/stats/commonteamyears](https://stats.nba.com/stats/commonteamyears)
6 |
7 | ##### Valid URL
8 | >[https://stats.nba.com/stats/commonteamyears?LeagueID=00](https://stats.nba.com/stats/commonteamyears?LeagueID=00)
9 |
10 | ## Parameters
11 | | API Parameter Name | Python Parameter Variable | Pattern | Required | Nullable |
12 | |-----------------------------------------------------------------------------------------------------------------|---------------------------|:---------:|:--------:|:--------:|
13 | | [_**LeagueID**_](https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md#LeagueID) | league_id | `^\d{2}$` | `Y` | |
14 |
15 | ## Data Sets
16 | #### TeamYears `team_years`
17 | ```text
18 | ['LEAGUE_ID', 'TEAM_ID', 'MIN_YEAR', 'MAX_YEAR', 'ABBREVIATION']
19 | ```
20 |
21 |
22 | ## JSON
23 | ```json
24 | {
25 | "data_sets": {
26 | "TeamYears": [
27 | "LEAGUE_ID",
28 | "TEAM_ID",
29 | "MIN_YEAR",
30 | "MAX_YEAR",
31 | "ABBREVIATION"
32 | ]
33 | },
34 | "endpoint": "CommonTeamYears",
35 | "last_validated_date": "2020-08-15",
36 | "nullable_parameters": [],
37 | "parameter_patterns": {
38 | "LeagueID": "^\\d{2}$"
39 | },
40 | "parameters": [
41 | "LeagueID"
42 | ],
43 | "required_parameters": [
44 | "LeagueID"
45 | ],
46 | "status": "success"
47 | }
48 | ```
49 |
50 | Last validated 2020-08-16
--------------------------------------------------------------------------------
/docs/nba_api/tools/stats/parameter_documentation_generator/generator.md:
--------------------------------------------------------------------------------
1 | # generator.py
2 | >/tools/parameter_documentation_generator/generator.py
3 |
4 | ## Objects
5 |
6 | ### `_get_class_information`(_`cls`_, \[_`variable_names_to_exclude=None`_\] )
7 |
8 | returns _`variables`_, _`variable_names_to_exclude`_
9 |
10 | This function will return variables inside of a class, as well as additional information such as if the variable is a default value or if it is a function.
11 |
12 | ### `get_library_classes`( \[_`module=mapping`_\] )
13 |
14 | This function will return a dictionary of library classes that contains classes and their variable contents.
15 |
16 | ### `get_parameter_map_parameters`( )
17 |
18 | returns _`parameters`_
19 |
20 | This function will return all parameters inside of our [`parameter_map`]().
21 |
22 | ### `get_parameter_map_patterns`( )
23 |
24 | returns _`parameters`_
25 |
26 | This function will return a dictionary of all parameter patterns inside of our [`parameter_map`]().
27 |
28 | ### `_get_variable_table_from_library_class`(_`library_class`_)
29 |
30 | returns _`variable_body`_
31 |
32 | This function will return the formatted variable body of the documentation.
33 |
34 | ### `_get_class_documentation_text`(_`parameter`_, _`pattern_info`_, _`library_classes`_)
35 |
36 | returns _`file_contents`_
37 |
38 | This function will return the contents of the documentation for the specified pattern information.
39 |
40 | ### `get_parameter_documentation_text`( )
41 |
42 | returns _`file_contents`_
43 |
44 | This function will return the file contents of the parameter documentation file.
45 |
46 | ### `generate_parameter_documentation_file`( \[_`directory='parameter_documentation'`_, _`file_name='endpoint_parameters.md'`_\] )
47 |
48 | This function will generate the documentation file for the `parameters.py` file.
49 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/_expected_data/dunkscoreleaders.py:
--------------------------------------------------------------------------------
1 | """Expected data structure for DunkScoreLeaders endpoint."""
2 |
3 | _EXPECTED_DATA = {
4 | "Dunks": [
5 | "GAME_ID",
6 | "GAME_DATE",
7 | "MATCHUP",
8 | "PERIOD",
9 | "GAME_CLOCK_TIME",
10 | "EVENT_NUM",
11 | "PLAYER_ID",
12 | "PLAYER_NAME",
13 | "FIRST_NAME",
14 | "LAST_NAME",
15 | "TEAM_ID",
16 | "TEAM_NAME",
17 | "TEAM_CITY",
18 | "TEAM_ABBREVIATION",
19 | "DUNK_SCORE",
20 | "JUMP_SUBSCORE",
21 | "POWER_SUBSCORE",
22 | "STYLE_SUBSCORE",
23 | "DEFENSIVE_CONTEST_SUBSCORE",
24 | "MAX_BALL_HEIGHT",
25 | "BALL_SPEED_THROUGH_RIM",
26 | "PLAYER_VERTICAL",
27 | "HANG_TIME",
28 | "TAKEOFF_DISTANCE",
29 | "REVERSE_DUNK",
30 | "DUNK_360",
31 | "THROUGH_THE_LEGS",
32 | "ALLEY_OOP",
33 | "TIP_IN",
34 | "SELF_OOP",
35 | "PLAYER_ROTATION",
36 | "PLAYER_LATERAL_SPEED",
37 | "BALL_DISTANCE_TRAVELED",
38 | "BALL_REACH_BACK",
39 | "TOTAL_BALL_ACCELERATION",
40 | "DUNKING_HAND",
41 | "JUMPING_FOOT",
42 | "PASS_LENGTH",
43 | "CATCHING_HAND",
44 | "CATCH_DISTANCE",
45 | "LATERAL_CATCH_DISTANCE",
46 | "PASSER_ID",
47 | "PASSER_NAME",
48 | "PASSER_FIRST_NAME",
49 | "PASSER_LAST_NAME",
50 | "PASS_RELEASE_POINT",
51 | "SHOOTER_ID",
52 | "SHOOTER_NAME",
53 | "SHOOTER_FIRST_NAME",
54 | "SHOOTER_LAST_NAME",
55 | "SHOT_RELEASE_POINT",
56 | "SHOT_LENGTH",
57 | "DEFENSIVE_CONTEST_LEVEL",
58 | "POSSIBLE_ATTEMPTED_CHARGE",
59 | "VIDEO_AVAILABLE",
60 | ]
61 | }
62 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/playerawards.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 |
4 |
5 | class PlayerAwards(Endpoint):
6 | endpoint = "playerawards"
7 | expected_data = {
8 | "PlayerAwards": [
9 | "PERSON_ID",
10 | "FIRST_NAME",
11 | "LAST_NAME",
12 | "TEAM",
13 | "DESCRIPTION",
14 | "ALL_NBA_TEAM_NUMBER",
15 | "SEASON",
16 | "MONTH",
17 | "WEEK",
18 | "CONFERENCE",
19 | "TYPE",
20 | "SUBTYPE1",
21 | "SUBTYPE2",
22 | "SUBTYPE3",
23 | ]
24 | }
25 |
26 | nba_response = None
27 | data_sets = None
28 | player_stats = None
29 | team_stats = None
30 | headers = None
31 |
32 | def __init__(
33 | self, player_id, proxy=None, headers=None, timeout=30, get_request=True
34 | ):
35 | self.proxy = proxy
36 | if headers is not None:
37 | self.headers = headers
38 | self.timeout = timeout
39 | self.parameters = {"PlayerID": player_id}
40 | if get_request:
41 | self.get_request()
42 |
43 | def get_request(self):
44 | self.nba_response = NBAStatsHTTP().send_api_request(
45 | endpoint=self.endpoint,
46 | parameters=self.parameters,
47 | proxy=self.proxy,
48 | headers=self.headers,
49 | timeout=self.timeout,
50 | )
51 | self.load_response()
52 |
53 | def load_response(self):
54 | data_sets = self.nba_response.get_data_sets()
55 | self.data_sets = [
56 | Endpoint.DataSet(data=data_set)
57 | for data_set_name, data_set in data_sets.items()
58 | ]
59 | self.player_awards = Endpoint.DataSet(data=data_sets["PlayerAwards"])
60 |
--------------------------------------------------------------------------------
/tests/integration/data/teamgamelog.py:
--------------------------------------------------------------------------------
1 | """
2 | Test data for TeamGameLog endpoint.
3 |
4 | GitHub Issues:
5 | - Endpoint was retired in v1.11.0 but is now working again (restored in v1.11.3)
6 |
7 | Expected response formats:
8 | - String: "success" | "has_data" | "empty" | "error"
9 | - Dict: {"status": "success", "min_rows": 1, "max_rows": 100}
10 | """
11 |
12 | # Endpoint class name
13 | ENDPOINT_CLASS = "TeamGameLog"
14 |
15 | # Test cases
16 | TEST_CASES = [
17 | {
18 | "description": "Lakers 2023-24 regular season",
19 | "params": {
20 | "team_id": "1610612747",
21 | "season": "2023-24",
22 | "season_type_all_star": "Regular Season",
23 | },
24 | "expected": {
25 | "status": "has_data",
26 | "validate_structure": True, # Enable strict validation
27 | },
28 | },
29 | {
30 | "description": "Lakers 2023-24 playoffs",
31 | "params": {
32 | "team_id": "1610612747",
33 | "season": "2023-24",
34 | "season_type_all_star": "Playoffs",
35 | },
36 | "expected": "has_data", # Lakers made playoffs in 2023-24
37 | },
38 | {
39 | "description": "Celtics 2023-24 regular season",
40 | "params": {
41 | "team_id": "1610612738",
42 | "season": "2023-24",
43 | "season_type_all_star": "Regular Season",
44 | },
45 | "expected": "has_data",
46 | },
47 | {
48 | "description": "Date range filter",
49 | "params": {
50 | "team_id": "1610612747",
51 | "season": "2023-24",
52 | "date_from_nullable": "01/01/2024",
53 | "date_to_nullable": "01/31/2024",
54 | },
55 | "expected": "has_data", # Should return games in January 2024
56 | },
57 | ]
58 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/shotchartleaguewide.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import LeagueID, Season
4 |
5 |
6 | class ShotChartLeagueWide(Endpoint):
7 | endpoint = "shotchartleaguewide"
8 | expected_data = {
9 | "League_Wide": [
10 | "GRID_TYPE",
11 | "SHOT_ZONE_BASIC",
12 | "SHOT_ZONE_AREA",
13 | "SHOT_ZONE_RANGE",
14 | "FGA",
15 | "FGM",
16 | "FG_PCT",
17 | ]
18 | }
19 |
20 | nba_response = None
21 | data_sets = None
22 | player_stats = None
23 | team_stats = None
24 | headers = None
25 |
26 | def __init__(
27 | self,
28 | league_id=LeagueID.default,
29 | season=Season.default,
30 | proxy=None,
31 | headers=None,
32 | timeout=30,
33 | get_request=True,
34 | ):
35 | self.proxy = proxy
36 | if headers is not None:
37 | self.headers = headers
38 | self.timeout = timeout
39 | self.parameters = {"LeagueID": league_id, "Season": season}
40 | if get_request:
41 | self.get_request()
42 |
43 | def get_request(self):
44 | self.nba_response = NBAStatsHTTP().send_api_request(
45 | endpoint=self.endpoint,
46 | parameters=self.parameters,
47 | proxy=self.proxy,
48 | headers=self.headers,
49 | timeout=self.timeout,
50 | )
51 | self.load_response()
52 |
53 | def load_response(self):
54 | data_sets = self.nba_response.get_data_sets()
55 | self.data_sets = [
56 | Endpoint.DataSet(data=data_set)
57 | for data_set_name, data_set in data_sets.items()
58 | ]
59 | self.league_wide = Endpoint.DataSet(data=data_sets["League_Wide"])
60 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/leaguedashptteamdefend_output.md:
--------------------------------------------------------------------------------
1 | LeagueDashPtTeamDefend:
2 |
3 | | TEAM_ID | TEAM_NAME | TEAM_ABBREVIATION | GP | G | FREQ | D_FGM | D_FGA | D_FG_PCT | NORMAL_FG_PCT | PCT_PLUSMINUS |
4 | |-----------:|:-----------------------|:--------------------|-----:|----:|-------:|--------:|--------:|-----------:|----------------:|----------------:|
5 | | 1610612750 | Minnesota Timberwolves | MIN | 82 | 82 | 1 | 3198 | 7112 | 0.45 | 0.473 | -0.023 |
6 | | 1610612738 | Boston Celtics | BOS | 82 | 82 | 1 | 3402 | 7509 | 0.453 | 0.473 | -0.02 |
7 | | 1610612760 | Oklahoma City Thunder | OKC | 82 | 82 | 1 | 3328 | 7321 | 0.455 | 0.472 | -0.018 |
8 | | 1610612745 | Houston Rockets | HOU | 82 | 82 | 1 | 3334 | 7201 | 0.463 | 0.474 | -0.011 |
9 | | 1610612740 | New Orleans Pelicans | NOP | 82 | 82 | 1 | 3293 | 7110 | 0.463 | 0.473 | -0.01 |
10 | | 1610612743 | Denver Nuggets | DEN | 81 | 81 | 1 | 3288 | 7119 | 0.462 | 0.472 | -0.01 |
11 | | 1610612756 | Phoenix Suns | PHX | 82 | 82 | 1 | 3444 | 7428 | 0.464 | 0.473 | -0.009 |
12 | | 1610612739 | Cleveland Cavaliers | CLE | 82 | 82 | 1 | 3323 | 7176 | 0.463 | 0.473 | -0.009 |
13 | | 1610612744 | Golden State Warriors | GSW | 82 | 82 | 1 | 3453 | 7415 | 0.466 | 0.474 | -0.008 |
14 | | 1610612748 | Miami Heat | MIA | 82 | 82 | 1 | 3297 | 7056 | 0.467 | 0.472 | -0.005 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/commonplayoffseries.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import LeagueID, Season
4 |
5 |
6 | class CommonPlayoffSeries(Endpoint):
7 | endpoint = "commonplayoffseries"
8 | expected_data = {
9 | "PlayoffSeries": [
10 | "GAME_ID",
11 | "HOME_TEAM_ID",
12 | "VISITOR_TEAM_ID",
13 | "SERIES_ID",
14 | "GAME_NUM",
15 | ]
16 | }
17 |
18 | nba_response = None
19 | data_sets = None
20 | player_stats = None
21 | team_stats = None
22 | headers = None
23 |
24 | def __init__(
25 | self,
26 | league_id=LeagueID.default,
27 | season=Season.default,
28 | series_id_nullable="",
29 | proxy=None,
30 | headers=None,
31 | timeout=30,
32 | get_request=True,
33 | ):
34 | self.proxy = proxy
35 | if headers is not None:
36 | self.headers = headers
37 | self.timeout = timeout
38 | self.parameters = {
39 | "LeagueID": league_id,
40 | "Season": season,
41 | "SeriesID": series_id_nullable,
42 | }
43 | if get_request:
44 | self.get_request()
45 |
46 | def get_request(self):
47 | self.nba_response = NBAStatsHTTP().send_api_request(
48 | endpoint=self.endpoint,
49 | parameters=self.parameters,
50 | proxy=self.proxy,
51 | headers=self.headers,
52 | timeout=self.timeout,
53 | )
54 | self.load_response()
55 |
56 | def load_response(self):
57 | data_sets = self.nba_response.get_data_sets()
58 | self.data_sets = [
59 | Endpoint.DataSet(data=data_set)
60 | for data_set_name, data_set in data_sets.items()
61 | ]
62 | self.playoff_series = Endpoint.DataSet(data=data_sets["PlayoffSeries"])
63 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/playergamestreakfinder_output.md:
--------------------------------------------------------------------------------
1 | PlayerGameStreakFinderResults:
2 |
3 | | PLAYER_NAME_LAST_FIRST | PLAYER_ID | GAMESTREAK | STARTDATE | ENDDATE | ACTIVESTREAK | NUMSEASONS | LASTSEASON | FIRSTSEASON |
4 | |:-------------------------|------------:|-------------:|:--------------------|:--------------------|---------------:|-------------:|:-------------|:--------------|
5 | | Carter, Vince | 1713 | 1541 | 1999-02-05T00:00:00 | 2020-03-11T00:00:00 | 1 | 22 | 2019-20 | 1998-99 |
6 | | Nowitzki, Dirk | 1717 | 1522 | 1999-02-05T00:00:00 | 2019-04-10T00:00:00 | 1 | 21 | 2018-19 | 1998-99 |
7 | | Stockton, John | 304 | 1504 | 1984-10-26T00:00:00 | 2003-04-16T00:00:00 | 1 | 19 | 2002-03 | 1984-85 |
8 | | James, LeBron | 2544 | 1492 | 2003-10-29T00:00:00 | 2024-04-14T00:00:00 | 1 | 21 | 2023-24 | 2003-04 |
9 | | Malone, Karl | 252 | 1476 | 1985-10-25T00:00:00 | 2004-04-14T00:00:00 | 1 | 19 | 2003-04 | 1985-86 |
10 | | Garnett, Kevin | 708 | 1462 | 1995-11-03T00:00:00 | 2016-01-23T00:00:00 | 1 | 21 | 2015-16 | 1995-96 |
11 | | Willis, Kevin | 788 | 1424 | 1984-10-26T00:00:00 | 2007-04-18T00:00:00 | 1 | 21 | 2006-07 | 1984-85 |
12 | | Terry, Jason | 1891 | 1410 | 1999-11-02T00:00:00 | 2018-04-11T00:00:00 | 1 | 19 | 2017-18 | 1999-00 |
13 | | Duncan, Tim | 1495 | 1392 | 1997-10-31T00:00:00 | 2016-04-12T00:00:00 | 1 | 19 | 2015-16 | 1997-98 |
14 | | Kidd, Jason | 467 | 1391 | 1994-11-05T00:00:00 | 2013-04-15T00:00:00 | 1 | 19 | 2012-13 | 1994-95 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/_expected_data/scoreboardv3.py:
--------------------------------------------------------------------------------
1 | """Expected data structure for ScoreboardV3 endpoint."""
2 |
3 | _EXPECTED_DATA = {
4 | "ScoreboardInfo": [
5 | "gameDate",
6 | "leagueId",
7 | "leagueName",
8 | ],
9 | "GameHeader": [
10 | "gameId",
11 | "gameCode",
12 | "gameStatus",
13 | "gameStatusText",
14 | "period",
15 | "gameClock",
16 | "gameTimeUTC",
17 | "gameEt",
18 | "regulationPeriods",
19 | "seriesGameNumber",
20 | "gameLabel",
21 | "gameSubLabel",
22 | "seriesText",
23 | "ifNecessary",
24 | "seriesConference",
25 | "poRoundDesc",
26 | "gameSubtype",
27 | "isNeutral",
28 | ],
29 | "LineScore": [
30 | "gameId",
31 | "teamId",
32 | "teamCity",
33 | "teamName",
34 | "teamTricode",
35 | "teamSlug",
36 | "wins",
37 | "losses",
38 | "score",
39 | "seed",
40 | "inBonus",
41 | "timeoutsRemaining",
42 | ],
43 | "GameLeaders": [
44 | "gameId",
45 | "teamId",
46 | "leaderType",
47 | "personId",
48 | "name",
49 | "playerSlug",
50 | "jerseyNum",
51 | "position",
52 | "teamTricode",
53 | "points",
54 | "rebounds",
55 | "assists",
56 | ],
57 | "TeamLeaders": [
58 | "gameId",
59 | "teamId",
60 | "leaderType",
61 | "personId",
62 | "name",
63 | "playerSlug",
64 | "jerseyNum",
65 | "position",
66 | "teamTricode",
67 | "points",
68 | "rebounds",
69 | "assists",
70 | "seasonLeadersFlag",
71 | ],
72 | "Broadcasters": [
73 | "gameId",
74 | "broadcasterType",
75 | "broadcasterId",
76 | "broadcastDisplay",
77 | "broadcasterTeamId",
78 | "broadcasterDescription",
79 | ],
80 | }
81 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug.yml:
--------------------------------------------------------------------------------
1 | name: Bug Report
2 | description: File a bug report
3 | title: "[Bug]: "
4 | labels: ["bug","triage"]
5 | body:
6 | - type: markdown
7 | attributes:
8 | value: |
9 | **STOP** Running on Azure, AWS, or GCP? The NBA blocks calls from cloud providers inclusive of products like [Colab](https://colab.research.google.com/).
10 |
11 | * For questions, ask in [Slack](https://join.slack.com/t/nbaapi/shared_invite/zt-1ipsuai9j-GjZjuP9S2~Uczuny1t74zA).
12 | * Before you file an issue read [Contributing tot he NBA API](https://github.com/swar/nba_api/blob/master/CONTRIBUTING.md).
13 | * Check to make sure someone hasn't already opened a similar [issue](https://github.com/microsoft/nba_api/issues).
14 | * If you find your issue already exists, make relevant comments and add your reaction. Use a reaction in place of a "+1" comment:
15 | * 👍 - upvote
16 | * 👎 - downvote
17 |
18 | - type: input
19 | id: version
20 | attributes:
21 | label: NBA API Version
22 | placeholder: ex. V1.1.11
23 | validations:
24 | required: true
25 |
26 | - type: textarea
27 | id: issue
28 | attributes:
29 | label: Issue
30 | description: |
31 | - Give as much detail as you can, including steps to reproduce, actual outcome, and expected outcome.
32 | placeholder: Brown beat Thompson to the spot and bodied him up, forcing him to change directions and nearly poking the ball away in the process. Then Brown recovered and used his length to cut off the pass to the corner. Finally, Brown stayed connected as he trailed Thompson on the cut through the lane, then used his athleticism and timing to erase the shot at the rim. Truly remarkable stuff.
33 | validations:
34 | required: true
35 |
36 | - type: textarea
37 | id: code
38 | attributes:
39 | label: Code
40 | description: Code snippet that demonstrates the issue or a link to a code repository that can easily be pull down to recreate the issue locally
41 | validations:
42 | required: false
43 |
--------------------------------------------------------------------------------
/tools/stats/endpoint_py_file_generator/template.py:
--------------------------------------------------------------------------------
1 | file_template = """from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP{imports}
3 |
4 |
5 | class {endpoint}(Endpoint):
6 | endpoint = '{endpoint_lowercase}'
7 | expected_data = {data_sets}
8 |
9 | nba_response = None
10 | data_sets = None
11 | player_stats = None
12 | team_stats = None
13 | headers = None
14 |
15 | def __init__(self,
16 | {arguments},
17 | proxy=None,
18 | headers=None,
19 | timeout=30,
20 | get_request=True):
21 | self.proxy = proxy
22 | if headers is not None:
23 | self.headers = headers
24 | self.timeout = timeout
25 | self.parameters = {{
26 | {parameters}
27 | }}
28 | if get_request:
29 | self.get_request()
30 |
31 | def get_request(self):
32 | self.nba_response = NBAStatsHTTP().send_api_request(
33 | endpoint=self.endpoint,
34 | parameters=self.parameters,
35 | proxy=self.proxy,
36 | headers=self.headers,
37 | timeout=self.timeout,
38 | )
39 | self.load_response()
40 |
41 | def load_response(self):
42 | data_sets = self.nba_response.get_data_sets()
43 | self.data_sets = [Endpoint.DataSet(data=data_set) for data_set_name, data_set in data_sets.items()]
44 | {data_set_variables}
45 | """
46 |
47 | data_set_template = (
48 | """ self.{variable_name} = Endpoint.DataSet(data=data_sets['{key_name}'])"""
49 | )
50 |
51 | imports_template = """\nfrom nba_api.stats.library.parameters import {imports_list}"""
52 |
53 | function_template = """ def {function_name}(self):
54 | return self.get_normalized_dict()['{data_header}']
55 | """
56 |
57 | parameter_template = """ '{nba_parameter}': {python_variable}"""
58 |
59 | argument_template = """ {python_variable}={default_value}"""
60 | no_default_argument_template = """ {python_variable}"""
61 |
--------------------------------------------------------------------------------
/tests/integration/data/teamdashlineups.py:
--------------------------------------------------------------------------------
1 | """Test data for TeamDashLineups endpoint."""
2 |
3 | # Endpoint class name (PascalCase)
4 | ENDPOINT_CLASS = "TeamDashLineups"
5 |
6 | # Test cases
7 | TEST_CASES = [
8 | {
9 | "description": "Cleveland Cavaliers 5-man lineups 2024-25",
10 | "params": {
11 | "team_id": 1610612739,
12 | "season": "2024-25",
13 | "season_type_all_star": "Regular Season",
14 | "group_quantity": 5,
15 | "measure_type_detailed_defense": "Base",
16 | "per_mode_detailed": "Totals",
17 | },
18 | "expected": "success"
19 | },
20 | {
21 | "description": "Lakers 2-man lineups 2023-24",
22 | "params": {
23 | "team_id": 1610612747,
24 | "season": "2023-24",
25 | "season_type_all_star": "Regular Season",
26 | "group_quantity": 2,
27 | "measure_type_detailed_defense": "Base",
28 | "per_mode_detailed": "PerGame",
29 | },
30 | "expected": "has_data"
31 | },
32 | {
33 | "description": "Warriors 3-man lineups playoffs 2023-24",
34 | "params": {
35 | "team_id": 1610612744,
36 | "season": "2023-24",
37 | "season_type_all_star": "Playoffs",
38 | "group_quantity": 3,
39 | "measure_type_detailed_defense": "Advanced",
40 | "per_mode_detailed": "Totals",
41 | },
42 | "expected": "success"
43 | },
44 | {
45 | "description": "Celtics 4-man lineups with date range",
46 | "params": {
47 | "team_id": 1610612738,
48 | "season": "2023-24",
49 | "season_type_all_star": "Regular Season",
50 | "group_quantity": 4,
51 | "measure_type_detailed_defense": "Base",
52 | "per_mode_detailed": "Totals",
53 | "date_from_nullable": "2024-01-01",
54 | "date_to_nullable": "2024-03-31",
55 | },
56 | "expected": "has_data"
57 | },
58 | ]
59 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/draftcombinedrillresults.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import LeagueID, SeasonYear
4 |
5 |
6 | class DraftCombineDrillResults(Endpoint):
7 | endpoint = "draftcombinedrillresults"
8 | expected_data = {
9 | "Results": [
10 | "TEMP_PLAYER_ID",
11 | "PLAYER_ID",
12 | "FIRST_NAME",
13 | "LAST_NAME",
14 | "PLAYER_NAME",
15 | "POSITION",
16 | "STANDING_VERTICAL_LEAP",
17 | "MAX_VERTICAL_LEAP",
18 | "LANE_AGILITY_TIME",
19 | "MODIFIED_LANE_AGILITY_TIME",
20 | "THREE_QUARTER_SPRINT",
21 | "BENCH_PRESS",
22 | ]
23 | }
24 |
25 | nba_response = None
26 | data_sets = None
27 | player_stats = None
28 | team_stats = None
29 | headers = None
30 |
31 | def __init__(
32 | self,
33 | league_id=LeagueID.default,
34 | season_year=SeasonYear.default,
35 | proxy=None,
36 | headers=None,
37 | timeout=30,
38 | get_request=True,
39 | ):
40 | self.proxy = proxy
41 | if headers is not None:
42 | self.headers = headers
43 | self.timeout = timeout
44 | self.parameters = {"LeagueID": league_id, "SeasonYear": season_year}
45 | if get_request:
46 | self.get_request()
47 |
48 | def get_request(self):
49 | self.nba_response = NBAStatsHTTP().send_api_request(
50 | endpoint=self.endpoint,
51 | parameters=self.parameters,
52 | proxy=self.proxy,
53 | headers=self.headers,
54 | timeout=self.timeout,
55 | )
56 | self.load_response()
57 |
58 | def load_response(self):
59 | data_sets = self.nba_response.get_data_sets()
60 | self.data_sets = [
61 | Endpoint.DataSet(data=data_set)
62 | for data_set_name, data_set in data_sets.items()
63 | ]
64 | self.results = Endpoint.DataSet(data=data_sets["Results"])
65 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints/playerawards.md:
--------------------------------------------------------------------------------
1 | # PlayerAwards
2 | ##### [nba_api/stats/endpoints/playerawards.py](https://github.com/swar/nba_api/blob/master/src/nba_api/stats/endpoints/playerawards.py)
3 |
4 | ##### Endpoint URL
5 | >[https://stats.nba.com/stats/playerawards](https://stats.nba.com/stats/playerawards)
6 |
7 | ##### Valid URL
8 | >[https://stats.nba.com/stats/playerawards?PlayerID=2544](https://stats.nba.com/stats/playerawards?PlayerID=2544)
9 |
10 | ## Parameters
11 | | API Parameter Name | Python Parameter Variable | Pattern | Required | Nullable |
12 | |-----------------------------------------------------------------------------------------------------------------|---------------------------|:-------:|:--------:|:--------:|
13 | | [_**PlayerID**_](https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md#PlayerID) | player_id | | `Y` | |
14 |
15 | ## Data Sets
16 | #### PlayerAwards `player_awards`
17 | ```text
18 | ['PERSON_ID', 'FIRST_NAME', 'LAST_NAME', 'TEAM', 'DESCRIPTION', 'ALL_NBA_TEAM_NUMBER', 'SEASON', 'MONTH', 'WEEK', 'CONFERENCE', 'TYPE', 'SUBTYPE1', 'SUBTYPE2', 'SUBTYPE3']
19 | ```
20 |
21 |
22 | ## JSON
23 | ```json
24 | {
25 | "data_sets": {
26 | "PlayerAwards": [
27 | "PERSON_ID",
28 | "FIRST_NAME",
29 | "LAST_NAME",
30 | "TEAM",
31 | "DESCRIPTION",
32 | "ALL_NBA_TEAM_NUMBER",
33 | "SEASON",
34 | "MONTH",
35 | "WEEK",
36 | "CONFERENCE",
37 | "TYPE",
38 | "SUBTYPE1",
39 | "SUBTYPE2",
40 | "SUBTYPE3"
41 | ]
42 | },
43 | "endpoint": "PlayerAwards",
44 | "last_validated_date": "2020-08-15",
45 | "nullable_parameters": [],
46 | "parameter_patterns": {
47 | "PlayerID": null
48 | },
49 | "parameters": [
50 | "PlayerID"
51 | ],
52 | "required_parameters": [
53 | "PlayerID"
54 | ],
55 | "status": "success"
56 | }
57 | ```
58 |
59 | Last validated 2020-08-16
--------------------------------------------------------------------------------
/tools/library/functions.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 |
4 | def capital_letter_replacement(match):
5 | return "_" + match.group(1).lower()
6 |
7 |
8 | def get_python_variable_name(parameter):
9 | find_replace_list = [
10 | ["OPPTOV", "OppTov"],
11 | ["OPPSTL", "OppStl"],
12 | ["OPPREB", "OppReb"],
13 | ["OPPPTSPAINT", "OppPtsPaint"],
14 | ["OPPPTSOFFTOV", "OppPtsOffTov"],
15 | ["OPPPTSFB", "OppPtsFb"],
16 | ["OPPPTS", "OppPts"],
17 | ["OPPPF", "OppPf"],
18 | ["OPPOREB", "OppOreb"],
19 | ["OPPFTM", "OppFtm"],
20 | ["OPPFTA", "OppFta"],
21 | ["OPPFT", "OppFt"],
22 | ["OPPFGM", "OppFgm"],
23 | ["OPPFGA", "OppFga"],
24 | ["OPPFG", "OppFg"],
25 | ["OPPDREB", "OppDreb"],
26 | ["OPPBLK", "OppBlk"],
27 | ["OPPAST", "OppAst"],
28 | ["IDL", "IdL"],
29 | ["PTSPAINT", "PtsPaint"],
30 | ["PTSOFFTOV", "PtsOffTov"],
31 | ["PTSFB", "PtsFb"],
32 | ["OREB", "Oreb"],
33 | ["NDCHANCE", "ndChance"],
34 | ["MINUTES", "Minutes"],
35 | ["PTS", "Pts"],
36 | ["POR", "PoR"],
37 | ["PF", "Pf"],
38 | ["PCT", "Pct"],
39 | ["LS", "Ls"],
40 | ["IDL", "IdL"],
41 | ["ID", "Id"],
42 | ["GROUP", "Group"],
43 | ["FTM", "Ftm"],
44 | ["FTA", "Fta"],
45 | ["FT", "Ft"],
46 | ["FGM", "Fgm"],
47 | ["FGA", "Fga"],
48 | ["FG", "Fg"],
49 | ["DREB", "Dreb"],
50 | ["DD", "Dd"],
51 | ["BLK", "Blk"],
52 | ["AST", "Ast"],
53 | ["WS", "Ws"],
54 | ["TOV", "Tov"],
55 | ["TD", "Td"],
56 | ["STL", "Stl"],
57 | ["REB", "Reb"],
58 | ]
59 |
60 | for find, replace in find_replace_list:
61 | parameter = parameter.replace(find, replace)
62 |
63 | if re.search("^[a-z]", parameter):
64 | parameter = "_" + parameter
65 | variable_name = re.sub(
66 | r"([A-Z])(?!$|Nullable|Round|Defend$)", capital_letter_replacement, parameter
67 | )[1:].lower()
68 | variable_name = variable_name.replace("__", "_")
69 | return variable_name
70 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/assistleaders.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import (
4 | LeagueID,
5 | PerModeSimple,
6 | PlayerOrTeam,
7 | Season,
8 | SeasonType,
9 | )
10 |
11 |
12 | class AssistLeaders(Endpoint):
13 | endpoint = "assistleaders"
14 | expected_data = {
15 | "AssistLeaders": ["RANK", "TEAM_ID", "TEAM_ABBREVIATION", "TEAM_NAME", "AST"]
16 | }
17 |
18 | nba_response = None
19 | data_sets = None
20 | player_stats = None
21 | team_stats = None
22 | headers = None
23 |
24 | def __init__(
25 | self,
26 | league_id=LeagueID.default,
27 | per_mode_simple=PerModeSimple.default,
28 | player_or_team=PlayerOrTeam.default,
29 | season=Season.default,
30 | season_type_playoffs=SeasonType.default,
31 | proxy=None,
32 | headers=None,
33 | timeout=30,
34 | get_request=True,
35 | ):
36 | self.proxy = proxy
37 | if headers is not None:
38 | self.headers = headers
39 | self.timeout = timeout
40 | self.parameters = {
41 | "LeagueID": league_id,
42 | "PerMode": per_mode_simple,
43 | "PlayerOrTeam": player_or_team,
44 | "Season": season,
45 | "SeasonType": season_type_playoffs,
46 | }
47 | if get_request:
48 | self.get_request()
49 |
50 | def get_request(self):
51 | self.nba_response = NBAStatsHTTP().send_api_request(
52 | endpoint=self.endpoint,
53 | parameters=self.parameters,
54 | proxy=self.proxy,
55 | headers=self.headers,
56 | timeout=self.timeout,
57 | )
58 | self.load_response()
59 |
60 | def load_response(self):
61 | data_sets = self.nba_response.get_data_sets()
62 | self.data_sets = [
63 | Endpoint.DataSet(data=data_set)
64 | for data_set_name, data_set in data_sets.items()
65 | ]
66 | self.assist_leaders = Endpoint.DataSet(data=data_sets["AssistLeaders"])
67 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/videostatus.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import GameDate, LeagueID
4 |
5 |
6 | class VideoStatus(Endpoint):
7 | endpoint = "videostatus"
8 | expected_data = {
9 | "VideoStatus": [
10 | "GAME_ID",
11 | "GAME_DATE",
12 | "VISITOR_TEAM_ID",
13 | "VISITOR_TEAM_CITY",
14 | "VISITOR_TEAM_NAME",
15 | "VISITOR_TEAM_ABBREVIATION",
16 | "HOME_TEAM_ID",
17 | "HOME_TEAM_CITY",
18 | "HOME_TEAM_NAME",
19 | "HOME_TEAM_ABBREVIATION",
20 | "GAME_STATUS",
21 | "GAME_STATUS_TEXT",
22 | "IS_AVAILABLE",
23 | "PT_XYZ_AVAILABLE",
24 | ]
25 | }
26 |
27 | nba_response = None
28 | data_sets = None
29 | player_stats = None
30 | team_stats = None
31 | headers = None
32 |
33 | def __init__(
34 | self,
35 | game_date=GameDate.default,
36 | league_id=LeagueID.default,
37 | proxy=None,
38 | headers=None,
39 | timeout=30,
40 | get_request=True,
41 | ):
42 | self.proxy = proxy
43 | if headers is not None:
44 | self.headers = headers
45 | self.timeout = timeout
46 | self.parameters = {"GameDate": game_date, "LeagueID": league_id}
47 | if get_request:
48 | self.get_request()
49 |
50 | def get_request(self):
51 | self.nba_response = NBAStatsHTTP().send_api_request(
52 | endpoint=self.endpoint,
53 | parameters=self.parameters,
54 | proxy=self.proxy,
55 | headers=self.headers,
56 | timeout=self.timeout,
57 | )
58 | self.load_response()
59 |
60 | def load_response(self):
61 | data_sets = self.nba_response.get_data_sets()
62 | self.data_sets = [
63 | Endpoint.DataSet(data=data_set)
64 | for data_set_name, data_set in data_sets.items()
65 | ]
66 | self.video_status = Endpoint.DataSet(data=data_sets["VideoStatus"])
67 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/franchiseleaders.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import LeagueIDNullable
4 |
5 |
6 | class FranchiseLeaders(Endpoint):
7 | endpoint = "franchiseleaders"
8 | expected_data = {
9 | "FranchiseLeaders": [
10 | "TEAM_ID",
11 | "PTS",
12 | "PTS_PERSON_ID",
13 | "PTS_PLAYER",
14 | "AST",
15 | "AST_PERSON_ID",
16 | "AST_PLAYER",
17 | "REB",
18 | "REB_PERSON_ID",
19 | "REB_PLAYER",
20 | "BLK",
21 | "BLK_PERSON_ID",
22 | "BLK_PLAYER",
23 | "STL",
24 | "STL_PERSON_ID",
25 | "STL_PLAYER",
26 | ]
27 | }
28 |
29 | nba_response = None
30 | data_sets = None
31 | player_stats = None
32 | team_stats = None
33 | headers = None
34 |
35 | def __init__(
36 | self,
37 | team_id,
38 | league_id_nullable=LeagueIDNullable.default,
39 | proxy=None,
40 | headers=None,
41 | timeout=30,
42 | get_request=True,
43 | ):
44 | self.proxy = proxy
45 | if headers is not None:
46 | self.headers = headers
47 | self.timeout = timeout
48 | self.parameters = {"TeamID": team_id, "LeagueID": league_id_nullable}
49 | if get_request:
50 | self.get_request()
51 |
52 | def get_request(self):
53 | self.nba_response = NBAStatsHTTP().send_api_request(
54 | endpoint=self.endpoint,
55 | parameters=self.parameters,
56 | proxy=self.proxy,
57 | headers=self.headers,
58 | timeout=self.timeout,
59 | )
60 | self.load_response()
61 |
62 | def load_response(self):
63 | data_sets = self.nba_response.get_data_sets()
64 | self.data_sets = [
65 | Endpoint.DataSet(data=data_set)
66 | for data_set_name, data_set in data_sets.items()
67 | ]
68 | self.franchise_leaders = Endpoint.DataSet(data=data_sets["FranchiseLeaders"])
69 |
--------------------------------------------------------------------------------
/tests/integration/data/leaguedashteamstats.py:
--------------------------------------------------------------------------------
1 | """Test data for LeagueDashTeamStats endpoint."""
2 |
3 | # Endpoint class name (PascalCase)
4 | ENDPOINT_CLASS = "LeagueDashTeamStats"
5 |
6 | # Test cases
7 | TEST_CASES = [
8 | {
9 | "description": "Atlanta Hawks 2023-24 regular season (IST bug regression test - should return GP=82)",
10 | "params": {
11 | "season": "2023-24",
12 | "team_id_nullable": "1610612737",
13 | "season_type_all_star": "Regular Season",
14 | },
15 | "expected": {
16 | "status": "success",
17 | "min_rows": 1,
18 | }
19 | },
20 | {
21 | "description": "All teams 2024-25 regular season base stats",
22 | "params": {
23 | "season": "2024-25",
24 | "season_type_all_star": "Regular Season",
25 | "measure_type_detailed_defense": "Base",
26 | "per_mode_detailed": "PerGame",
27 | },
28 | "expected": {
29 | "status": "success",
30 | "min_rows": 30
31 | }
32 | },
33 | {
34 | "description": "Lakers 2023-24 playoffs",
35 | "params": {
36 | "season": "2023-24",
37 | "team_id_nullable": "1610612747",
38 | "season_type_all_star": "Playoffs",
39 | },
40 | "expected": "success"
41 | },
42 | {
43 | "description": "Warriors 2023-24 advanced stats",
44 | "params": {
45 | "season": "2023-24",
46 | "team_id_nullable": "1610612744",
47 | "season_type_all_star": "Regular Season",
48 | "measure_type_detailed_defense": "Advanced",
49 | "per_mode_detailed": "PerGame",
50 | },
51 | "expected": "has_data"
52 | },
53 | {
54 | "description": "Eastern Conference 2023-24",
55 | "params": {
56 | "season": "2023-24",
57 | "season_type_all_star": "Regular Season",
58 | "conference_nullable": "East",
59 | },
60 | "expected": {
61 | "status": "success",
62 | "min_rows": 15
63 | }
64 | },
65 | ]
66 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints/shotchartleaguewide.md:
--------------------------------------------------------------------------------
1 | # ShotChartLeagueWide
2 | ##### [nba_api/stats/endpoints/shotchartleaguewide.py](https://github.com/swar/nba_api/blob/master/src/nba_api/stats/endpoints/shotchartleaguewide.py)
3 |
4 | ##### Endpoint URL
5 | >[https://stats.nba.com/stats/shotchartleaguewide](https://stats.nba.com/stats/shotchartleaguewide)
6 |
7 | ##### Valid URL
8 | >[https://stats.nba.com/stats/shotchartleaguewide?LeagueID=00&Season=2019-20](https://stats.nba.com/stats/shotchartleaguewide?LeagueID=00&Season=2019-20)
9 |
10 | ## Parameters
11 | | API Parameter Name | Python Parameter Variable | Pattern | Required | Nullable |
12 | |-----------------------------------------------------------------------------------------------------------------|---------------------------|:-------:|:--------:|:--------:|
13 | | [_**LeagueID**_](https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md#LeagueID) | league_id | | `Y` | |
14 | | [_**Season**_](https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md#Season) | season | | `Y` | |
15 |
16 | ## Data Sets
17 | #### League_Wide `league_wide`
18 | ```text
19 | ['GRID_TYPE', 'SHOT_ZONE_BASIC', 'SHOT_ZONE_AREA', 'SHOT_ZONE_RANGE', 'FGA', 'FGM', 'FG_PCT']
20 | ```
21 |
22 |
23 | ## JSON
24 | ```json
25 | {
26 | "data_sets": {
27 | "League_Wide": [
28 | "GRID_TYPE",
29 | "SHOT_ZONE_BASIC",
30 | "SHOT_ZONE_AREA",
31 | "SHOT_ZONE_RANGE",
32 | "FGA",
33 | "FGM",
34 | "FG_PCT"
35 | ]
36 | },
37 | "endpoint": "ShotChartLeagueWide",
38 | "last_validated_date": "2020-08-15",
39 | "nullable_parameters": [],
40 | "parameter_patterns": {
41 | "LeagueID": null,
42 | "Season": null
43 | },
44 | "parameters": [
45 | "LeagueID",
46 | "Season"
47 | ],
48 | "required_parameters": [
49 | "LeagueID",
50 | "Season"
51 | ],
52 | "status": "success"
53 | }
54 | ```
55 |
56 | Last validated 2020-08-16
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/teamgamestreakfinder_output.md:
--------------------------------------------------------------------------------
1 | TeamGameStreakFinderParametersResults:
2 |
3 | | TEAM_NAME | TEAM_ID | GAMESTREAK | STARTDATE | ENDDATE | ACTIVESTREAK | NUMSEASONS | LASTSEASON | FIRSTSEASON | ABBREVIATION |
4 | |:-----------------------|-----------:|-------------:|:--------------------|:--------------------|---------------:|-------------:|:-------------|:--------------|:---------------|
5 | | San Antonio Spurs | 1610612759 | 3390 | 1983-10-29T00:00:00 | 2024-04-14T00:00:00 | 1 | 41 | 2023-24 | 1983-84 | |
6 | | Philadelphia 76ers | 1610612755 | 3388 | 1983-10-28T00:00:00 | 2024-04-14T00:00:00 | 1 | 41 | 2023-24 | 1983-84 | |
7 | | Los Angeles Lakers | 1610612747 | 3387 | 1983-10-28T00:00:00 | 2024-04-14T00:00:00 | 1 | 41 | 2023-24 | 1983-84 | |
8 | | Dallas Mavericks | 1610612742 | 3386 | 1983-10-29T00:00:00 | 2024-04-14T00:00:00 | 1 | 41 | 2023-24 | 1983-84 | |
9 | | Golden State Warriors | 1610612744 | 3380 | 1983-10-28T00:00:00 | 2024-04-14T00:00:00 | 1 | 41 | 2023-24 | 1983-84 | |
10 | | Portland Trail Blazers | 1610612757 | 3378 | 1983-10-28T00:00:00 | 2024-04-14T00:00:00 | 1 | 41 | 2023-24 | 1983-84 | |
11 | | Houston Rockets | 1610612745 | 3378 | 1983-10-29T00:00:00 | 2024-04-14T00:00:00 | 1 | 41 | 2023-24 | 1983-84 | |
12 | | Utah Jazz | 1610612762 | 3376 | 1983-10-28T00:00:00 | 2024-04-14T00:00:00 | 1 | 41 | 2023-24 | 1983-84 | |
13 | | Phoenix Suns | 1610612756 | 3375 | 1983-10-29T00:00:00 | 2024-04-14T00:00:00 | 1 | 41 | 2023-24 | 1983-84 | |
14 | | Boston Celtics | 1610612738 | 3374 | 1983-10-28T00:00:00 | 2024-04-14T00:00:00 | 1 | 41 | 2023-24 | 1983-84 | |
--------------------------------------------------------------------------------
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2.1
2 |
3 | orbs:
4 | snyk: snyk/snyk@1.4.0
5 |
6 | references:
7 | python_images: &python_images
8 | - "cimg/python:3.10"
9 | - "cimg/python:3.11"
10 | - "cimg/python:3.12"
11 | - "cimg/python:3.13"
12 | default_image: &default_image cimg/python:3.13
13 |
14 | jobs:
15 | main:
16 | parameters:
17 | image:
18 | type: string
19 | circle_pr_number:
20 | type: string
21 | default: $CIRCLE_PR_NUMBER
22 |
23 | docker:
24 | - image: <>
25 |
26 | steps:
27 | - checkout
28 | - run:
29 | name: install dependencies
30 | command: poetry install --no-ansi
31 | - unless:
32 | condition: << parameters.circle_pr_number >>
33 | steps:
34 | - snyk/scan
35 | - run:
36 | name: run tests
37 | command: poetry run pytest
38 | - run:
39 | name: run flake8
40 | command: poetry run flake8
41 |
42 | release:
43 | docker:
44 | - image: *default_image
45 | steps:
46 | - checkout
47 | - run:
48 | name: Install dependencies
49 | command: poetry install --no-ansi
50 | - run:
51 | name: Configure git
52 | command: |
53 | git config user.name "CircleCI"
54 | git config user.email "ci@circleci.com"
55 | - run:
56 | name: Configure authentication
57 | command: |
58 | export REPOSITORY_USERNAME=__token__
59 | export REPOSITORY_PASSWORD=$PYPI_TOKEN
60 | poetry config pypi-token.pypi $PYPI_TOKEN
61 | - run:
62 | name: Run semantic release
63 | command: |
64 | export REPOSITORY_USERNAME=__token__
65 | export REPOSITORY_PASSWORD=$PYPI_TOKEN
66 | export GITHUB_TOKEN=$GITHUB_TOKEN
67 | poetry run semantic-release publish
68 | workflows:
69 | build:
70 | jobs:
71 | - main:
72 | matrix:
73 | parameters:
74 | image: *python_images
75 | - release:
76 | requires:
77 | - main
78 | filters:
79 | branches:
80 | only: master
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/commonplayerinfo_output.md:
--------------------------------------------------------------------------------
1 | CommonPlayerInfo:
2 |
3 | | PERSON_ID | FIRST_NAME | LAST_NAME | DISPLAY_FIRST_LAST | DISPLAY_LAST_COMMA_FIRST | DISPLAY_FI_LAST | PLAYER_SLUG | BIRTHDATE | SCHOOL | COUNTRY | LAST_AFFILIATION | HEIGHT | WEIGHT | SEASON_EXP | JERSEY | POSITION | ROSTERSTATUS | GAMES_PLAYED_CURRENT_SEASON_FLAG | TEAM_ID | TEAM_NAME | TEAM_ABBREVIATION | TEAM_CODE | TEAM_CITY | PLAYERCODE | FROM_YEAR | TO_YEAR | DLEAGUE_FLAG | NBA_FLAG | GAMES_PLAYED_FLAG | DRAFT_YEAR | DRAFT_ROUND | DRAFT_NUMBER | GREATEST_75_FLAG |
4 | |------------:|:-------------|:------------|:---------------------|:---------------------------|:------------------|:--------------|:--------------------|:---------|:----------|:-------------------|:---------|---------:|-------------:|---------:|:--------------|:---------------|:-----------------------------------|-----------:|:------------|:--------------------|:------------|:------------|:-------------|------------:|----------:|:---------------|:-----------|:--------------------|-------------:|--------------:|---------------:|:-------------------|
5 | | 1628369 | Jayson | Tatum | Jayson Tatum | Tatum, Jayson | J. Tatum | jayson-tatum | 1998-03-03T00:00:00 | Duke | USA | Duke/USA | 6-8 | 210 | 6 | 0 | Forward-Guard | Active | Y | 1610612738 | Celtics | BOS | celtics | Boston | jayson_tatum | 2017 | 2023 | N | Y | Y | 2017 | 1 | 3 | N |
6 |
7 | PlayerHeadlineStats:
8 |
9 | | PLAYER_ID | PLAYER_NAME | TimeFrame | PTS | AST | REB | PIE |
10 | |------------:|:--------------|:------------|------:|------:|------:|------:|
11 | | 1628369 | Jayson Tatum | 2023-24 | 26.9 | 4.9 | 8.1 | 0.155 |
12 |
13 | AvailableSeasons:
14 |
15 | | SEASON_ID |
16 | |------------:|
17 | | 12017 |
18 | | 22017 |
19 | | 42017 |
20 | | 12018 |
21 | | 22018 |
22 | | 42018 |
23 | | 12019 |
24 | | 22019 |
25 | | 32019 |
26 | | 42019 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/draftcombineplayeranthro.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import LeagueID, SeasonYear
4 |
5 |
6 | class DraftCombinePlayerAnthro(Endpoint):
7 | endpoint = "draftcombineplayeranthro"
8 | expected_data = {
9 | "Results": [
10 | "TEMP_PLAYER_ID",
11 | "PLAYER_ID",
12 | "FIRST_NAME",
13 | "LAST_NAME",
14 | "PLAYER_NAME",
15 | "POSITION",
16 | "HEIGHT_WO_SHOES",
17 | "HEIGHT_WO_SHOES_FT_IN",
18 | "HEIGHT_W_SHOES",
19 | "HEIGHT_W_SHOES_FT_IN",
20 | "WEIGHT",
21 | "WINGSPAN",
22 | "WINGSPAN_FT_IN",
23 | "STANDING_REACH",
24 | "STANDING_REACH_FT_IN",
25 | "BODY_FAT_PCT",
26 | "HAND_LENGTH",
27 | "HAND_WIDTH",
28 | ]
29 | }
30 |
31 | nba_response = None
32 | data_sets = None
33 | player_stats = None
34 | team_stats = None
35 | headers = None
36 |
37 | def __init__(
38 | self,
39 | league_id=LeagueID.default,
40 | season_year=SeasonYear.default,
41 | proxy=None,
42 | headers=None,
43 | timeout=30,
44 | get_request=True,
45 | ):
46 | self.proxy = proxy
47 | if headers is not None:
48 | self.headers = headers
49 | self.timeout = timeout
50 | self.parameters = {"LeagueID": league_id, "SeasonYear": season_year}
51 | if get_request:
52 | self.get_request()
53 |
54 | def get_request(self):
55 | self.nba_response = NBAStatsHTTP().send_api_request(
56 | endpoint=self.endpoint,
57 | parameters=self.parameters,
58 | proxy=self.proxy,
59 | headers=self.headers,
60 | timeout=self.timeout,
61 | )
62 | self.load_response()
63 |
64 | def load_response(self):
65 | data_sets = self.nba_response.get_data_sets()
66 | self.data_sets = [
67 | Endpoint.DataSet(data=data_set)
68 | for data_set_name, data_set in data_sets.items()
69 | ]
70 | self.results = Endpoint.DataSet(data=data_sets["Results"])
71 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/playbyplay.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import EndPeriod, StartPeriod
4 |
5 |
6 | class PlayByPlay(Endpoint):
7 | endpoint = "playbyplay"
8 | expected_data = {
9 | "AvailableVideo": ["VIDEO_AVAILABLE_FLAG"],
10 | "PlayByPlay": [
11 | "GAME_ID",
12 | "EVENTNUM",
13 | "EVENTMSGTYPE",
14 | "EVENTMSGACTIONTYPE",
15 | "PERIOD",
16 | "WCTIMESTRING",
17 | "PCTIMESTRING",
18 | "HOMEDESCRIPTION",
19 | "NEUTRALDESCRIPTION",
20 | "VISITORDESCRIPTION",
21 | "SCORE",
22 | "SCOREMARGIN",
23 | ],
24 | }
25 |
26 | nba_response = None
27 | data_sets = None
28 | player_stats = None
29 | team_stats = None
30 | headers = None
31 |
32 | def __init__(
33 | self,
34 | game_id,
35 | end_period=EndPeriod.default,
36 | start_period=StartPeriod.default,
37 | proxy=None,
38 | headers=None,
39 | timeout=30,
40 | get_request=True,
41 | ):
42 | self.proxy = proxy
43 | if headers is not None:
44 | self.headers = headers
45 | self.timeout = timeout
46 | self.parameters = {
47 | "GameID": game_id,
48 | "EndPeriod": end_period,
49 | "StartPeriod": start_period,
50 | }
51 | if get_request:
52 | self.get_request()
53 |
54 | def get_request(self):
55 | self.nba_response = NBAStatsHTTP().send_api_request(
56 | endpoint=self.endpoint,
57 | parameters=self.parameters,
58 | proxy=self.proxy,
59 | headers=self.headers,
60 | timeout=self.timeout,
61 | )
62 | self.load_response()
63 |
64 | def load_response(self):
65 | data_sets = self.nba_response.get_data_sets()
66 | self.data_sets = [
67 | Endpoint.DataSet(data=data_set)
68 | for data_set_name, data_set in data_sets.items()
69 | ]
70 | self.available_video = Endpoint.DataSet(data=data_sets["AvailableVideo"])
71 | self.play_by_play = Endpoint.DataSet(data=data_sets["PlayByPlay"])
72 |
--------------------------------------------------------------------------------
/docs/nba_api/library/http.md:
--------------------------------------------------------------------------------
1 | # http.py
2 | >/nba_api/library/http.py
3 |
4 | The purpose of this module is to connect to the NBA website as well as store the response in a `NBAResponse` class.
5 |
6 | This should be considered as a base file to build on-top of an NBA API location.
7 |
8 | ## `DEBUG`,`DEBUG_STORAGE`, `PROXY`
9 |
10 | These variables are set in [`/nba_api/debug.py`](/docs/nba_api/debug.md)
11 |
12 |
13 | ## class `NBAResponse`
14 |
15 | #### `__init__` (_`response`_, _`status_code`_, _`url`_)
16 |
17 | Loads the response text, status_code, and url on initiation.
18 |
19 | #### `get_response`( )
20 |
21 | returns `response`
22 |
23 | This method will return the response returned by a request.
24 |
25 | #### `get_dict`( )
26 |
27 | This method will return a `dictionary` of the response. It wil fail if the response is not a json.
28 |
29 | #### `get_json`( )
30 |
31 | This method will return a `json` string of the response. It wil fail if the response is not a json.
32 |
33 | #### `valid_json`( )
34 |
35 | This method is used to help determine if the response is a valid `json` response.
36 |
37 | #### `get_url`( )
38 |
39 | This method will return the url that we used to request the result.
40 |
41 |
42 | ## class `NBAHTTP`
43 |
44 | #### `nba_response`
45 |
46 | This is used to set the `NBAResponse` class.
47 |
48 | #### `base_url`
49 |
50 | This is used to set the base url of requests.
51 |
52 | #### `parameters`
53 |
54 | This is used to load the parameters needed for the requests.
55 |
56 | #### `headers`
57 |
58 | This is used to set the headers of requests.
59 |
60 | #### `clean_contents`(_`contents`_)
61 |
62 | This method is used to clean any contents if any invalid values are returned.
63 |
64 | #### `send_api_request`(_`endpoint`_, _`parameters`_ \[, _`referer=None`_, _`proxy=None`_, _`headers=None`_, _`timeout=None`_, _`raise_exception_on_error=False`_\] )
65 |
66 | This method will send out an api request with the given endpoint, parameters, referer, proxy, header, and timeout. You can also enable the option to raise an exception any time a valid `json` response is not returned.
67 |
68 | If the value supplied for proxy or headers are `null`, it will use the default system setting. In order to override the system settings, please supply it an empty `string` or `dictionary`.
69 |
70 | The default timeout for each request is 30 seconds.
--------------------------------------------------------------------------------
/.pylintrc:
--------------------------------------------------------------------------------
1 | [MAIN]
2 | # Python version to target
3 | py-version=3.10
4 |
5 | # Use multiple processes to speed up Pylint
6 | jobs=0
7 |
8 | # Allow loading of arbitrary C extensions
9 | unsafe-load-any-extension=no
10 |
11 | [MESSAGES CONTROL]
12 | # Disable specific warnings and convention checks
13 | disable=
14 | missing-module-docstring,
15 | missing-class-docstring,
16 | missing-function-docstring,
17 | too-few-public-methods,
18 | too-many-instance-attributes,
19 | too-many-arguments,
20 | too-many-positional-arguments,
21 | too-many-locals,
22 | too-many-branches,
23 | too-many-statements,
24 | line-too-long,
25 | invalid-name,
26 | fixme,
27 | import-error,
28 | broad-exception-raised,
29 | redefined-builtin,
30 | consider-using-f-string,
31 | unspecified-encoding,
32 | consider-using-with,
33 | attribute-defined-outside-init,
34 | dangerous-default-value,
35 | no-member,
36 | consider-using-from-import
37 |
38 | [FORMAT]
39 | # Maximum number of characters on a single line (aligned with Black)
40 | max-line-length=88
41 |
42 | # Maximum number of lines in a module
43 | max-module-lines=1000
44 |
45 | [DESIGN]
46 | # Maximum number of arguments for function / method
47 | max-args=7
48 |
49 | # Maximum number of attributes for a class
50 | max-attributes=10
51 |
52 | # Maximum number of boolean expressions in an if statement
53 | max-bool-expr=5
54 |
55 | # Maximum number of branch for function / method body
56 | max-branches=15
57 |
58 | # Maximum number of locals for function / method body
59 | max-locals=20
60 |
61 | # Maximum number of public methods for a class
62 | max-public-methods=20
63 |
64 | # Maximum number of return / yield for function / method body
65 | max-returns=6
66 |
67 | # Maximum number of statements in function / method body
68 | max-statements=60
69 |
70 | [TYPECHECK]
71 | # List of members which are set dynamically
72 | generated-members=
73 |
74 | [SIMILARITIES]
75 | # Minimum lines number of a similarity
76 | min-similarity-lines=4
77 |
78 | # Ignore comments when computing similarities
79 | ignore-comments=yes
80 |
81 | # Ignore docstrings when computing similarities
82 | ignore-docstrings=yes
83 |
84 | # Ignore imports when computing similarities
85 | ignore-imports=yes
86 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/infographicfanduelplayer.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 |
4 |
5 | class InfographicFanDuelPlayer(Endpoint):
6 | endpoint = "infographicfanduelplayer"
7 | expected_data = {
8 | "FanDuelPlayer": [
9 | "PLAYER_ID",
10 | "PLAYER_NAME",
11 | "TEAM_ID",
12 | "TEAM_NAME",
13 | "TEAM_ABBREVIATION",
14 | "JERSEY_NUM",
15 | "PLAYER_POSITION",
16 | "LOCATION",
17 | "FAN_DUEL_PTS",
18 | "NBA_FANTASY_PTS",
19 | "USG_PCT",
20 | "MIN",
21 | "FGM",
22 | "FGA",
23 | "FG_PCT",
24 | "FG3M",
25 | "FG3A",
26 | "FG3_PCT",
27 | "FTM",
28 | "FTA",
29 | "FT_PCT",
30 | "OREB",
31 | "DREB",
32 | "REB",
33 | "AST",
34 | "TOV",
35 | "STL",
36 | "BLK",
37 | "BLKA",
38 | "PF",
39 | "PFD",
40 | "PTS",
41 | "PLUS_MINUS",
42 | ]
43 | }
44 |
45 | nba_response = None
46 | data_sets = None
47 | player_stats = None
48 | team_stats = None
49 | headers = None
50 |
51 | def __init__(self, game_id, proxy=None, headers=None, timeout=30, get_request=True):
52 | self.proxy = proxy
53 | if headers is not None:
54 | self.headers = headers
55 | self.timeout = timeout
56 | self.parameters = {"GameID": game_id}
57 | if get_request:
58 | self.get_request()
59 |
60 | def get_request(self):
61 | self.nba_response = NBAStatsHTTP().send_api_request(
62 | endpoint=self.endpoint,
63 | parameters=self.parameters,
64 | proxy=self.proxy,
65 | headers=self.headers,
66 | timeout=self.timeout,
67 | )
68 | self.load_response()
69 |
70 | def load_response(self):
71 | data_sets = self.nba_response.get_data_sets()
72 | self.data_sets = [
73 | Endpoint.DataSet(data=data_set)
74 | for data_set_name, data_set in data_sets.items()
75 | ]
76 | self.fan_duel_player = Endpoint.DataSet(data=data_sets["FanDuelPlayer"])
77 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/teamhistoricalleaders.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import LeagueID, SeasonID
4 |
5 |
6 | class TeamHistoricalLeaders(Endpoint):
7 | endpoint = "teamhistoricalleaders"
8 | expected_data = {
9 | "CareerLeadersByTeam": [
10 | "TEAM_ID",
11 | "PTS",
12 | "PTS_PERSON_ID",
13 | "PTS_PLAYER",
14 | "AST",
15 | "AST_PERSON_ID",
16 | "AST_PLAYER",
17 | "REB",
18 | "REB_PERSON_ID",
19 | "REB_PLAYER",
20 | "BLK",
21 | "BLK_PERSON_ID",
22 | "BLK_PLAYER",
23 | "STL",
24 | "STL_PERSON_ID",
25 | "STL_PLAYER",
26 | "SEASON_YEAR",
27 | ]
28 | }
29 |
30 | nba_response = None
31 | data_sets = None
32 | player_stats = None
33 | team_stats = None
34 | headers = None
35 |
36 | def __init__(
37 | self,
38 | team_id,
39 | league_id=LeagueID.default,
40 | season_id=SeasonID.default,
41 | proxy=None,
42 | headers=None,
43 | timeout=30,
44 | get_request=True,
45 | ):
46 | self.proxy = proxy
47 | if headers is not None:
48 | self.headers = headers
49 | self.timeout = timeout
50 | self.parameters = {
51 | "TeamID": team_id,
52 | "LeagueID": league_id,
53 | "SeasonID": season_id,
54 | }
55 | if get_request:
56 | self.get_request()
57 |
58 | def get_request(self):
59 | self.nba_response = NBAStatsHTTP().send_api_request(
60 | endpoint=self.endpoint,
61 | parameters=self.parameters,
62 | proxy=self.proxy,
63 | headers=self.headers,
64 | timeout=self.timeout,
65 | )
66 | self.load_response()
67 |
68 | def load_response(self):
69 | data_sets = self.nba_response.get_data_sets()
70 | self.data_sets = [
71 | Endpoint.DataSet(data=data_set)
72 | for data_set_name, data_set in data_sets.items()
73 | ]
74 | self.career_leaders_by_team = Endpoint.DataSet(
75 | data=data_sets["CareerLeadersByTeam"]
76 | )
77 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/commonallplayers.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import LeagueID, Season
4 |
5 |
6 | class CommonAllPlayers(Endpoint):
7 | endpoint = "commonallplayers"
8 | expected_data = {
9 | "CommonAllPlayers": [
10 | "PERSON_ID",
11 | "DISPLAY_LAST_COMMA_FIRST",
12 | "DISPLAY_FIRST_LAST",
13 | "ROSTERSTATUS",
14 | "FROM_YEAR",
15 | "TO_YEAR",
16 | "PLAYERCODE",
17 | "PLAYER_SLUG",
18 | "TEAM_ID",
19 | "TEAM_CITY",
20 | "TEAM_NAME",
21 | "TEAM_ABBREVIATION",
22 | "TEAM_CODE",
23 | "TEAM_SLUG",
24 | "GAMES_PLAYED_FLAG",
25 | "OTHERLEAGUE_EXPERIENCE_CH",
26 | ]
27 | }
28 |
29 | nba_response = None
30 | data_sets = None
31 | player_stats = None
32 | team_stats = None
33 | headers = None
34 |
35 | def __init__(
36 | self,
37 | is_only_current_season=0,
38 | league_id=LeagueID.default,
39 | season=Season.default,
40 | proxy=None,
41 | headers=None,
42 | timeout=30,
43 | get_request=True,
44 | ):
45 | self.proxy = proxy
46 | if headers is not None:
47 | self.headers = headers
48 | self.timeout = timeout
49 | self.parameters = {
50 | "IsOnlyCurrentSeason": is_only_current_season,
51 | "LeagueID": league_id,
52 | "Season": season,
53 | }
54 | if get_request:
55 | self.get_request()
56 |
57 | def get_request(self):
58 | self.nba_response = NBAStatsHTTP().send_api_request(
59 | endpoint=self.endpoint,
60 | parameters=self.parameters,
61 | proxy=self.proxy,
62 | headers=self.headers,
63 | timeout=self.timeout,
64 | )
65 | self.load_response()
66 |
67 | def load_response(self):
68 | data_sets = self.nba_response.get_data_sets()
69 | self.data_sets = [
70 | Endpoint.DataSet(data=data_set)
71 | for data_set_name, data_set in data_sets.items()
72 | ]
73 | self.common_all_players = Endpoint.DataSet(data=data_sets["CommonAllPlayers"])
74 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # NBA-API Specifics
2 | static_files/
3 |
4 | # Byte-compiled / optimized / DLL files
5 | __pycache__/
6 | *.py[cod]
7 | *$py.class
8 |
9 | # C extensions
10 | *.so
11 |
12 | # Distribution / packaging
13 | .Python
14 | build/
15 | develop-eggs/
16 | dist/
17 | downloads/
18 | eggs/
19 | .eggs/
20 | lib/
21 | lib64/
22 | parts/
23 | sdist/
24 | var/
25 | wheels/
26 | *.egg-info/
27 | .installed.cfg
28 | *.egg
29 | MANIFEST
30 |
31 | # PyInstaller
32 | # Usually these files are written by a python script from a template
33 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
34 | *.manifest
35 | *.spec
36 |
37 | # Installer logs
38 | pip-log.txt
39 | pip-delete-this-directory.txt
40 |
41 | # Unit test / coverage reports
42 | htmlcov/
43 | .tox/
44 | .coverage
45 | .coverage.*
46 | .cache
47 | nosetests.xml
48 | coverage.xml
49 | *.cover
50 | .hypothesis/
51 | .pytest_cache/
52 |
53 | # Snyk
54 | .dccache
55 |
56 | # Translations
57 | *.mo
58 | *.pot
59 |
60 | # Django stuff:
61 | *.log
62 | local_settings.py
63 | db.sqlite3
64 |
65 | # Flask stuff:
66 | instance/
67 | .webassets-cache
68 |
69 | # Scrapy stuff:
70 | .scrapy
71 |
72 | # Sphinx documentation
73 | docs/_build/
74 |
75 | # PyBuilder
76 | target/
77 |
78 | # Jupyter Notebook
79 | .ipynb_checkpoints
80 |
81 | # pyenv
82 | .python-version
83 |
84 | # celery beat schedule file
85 | celerybeat-schedule
86 |
87 | # SageMath parsed files
88 | *.sage.py
89 |
90 | # Environments
91 | .env
92 | .venv
93 | env/
94 | venv/
95 | ENV/
96 | env.bak/
97 | venv.bak/
98 |
99 | # Spyder project settings
100 | .spyderproject
101 | .spyproject
102 |
103 | # Rope project settings
104 | .ropeproject
105 |
106 | # mkdocs documentation
107 | /site
108 |
109 | # mypy
110 | .mypy_cache/
111 |
112 | # PyCharm
113 | .idea
114 |
115 | # Debug Files
116 | nba_api/nba_api/library/debug/
117 | nba_api/scripts/endpoint_analysis/
118 | nba_api/scripts/endpoint_documentation/
119 | nba_api/scripts/endpoint_files/
120 | nba_api/library/debug/
121 |
122 | # Visual Studio Code
123 | .vscode/*
124 | !.vscode/settings.json
125 | !.vscode/tasks.json
126 | !.vscode/launch.json
127 | !.vscode/extensions.json
128 | !.vscode/*.code-snippets
129 |
130 | # Local History for Visual Studio Code
131 | .history/
132 |
133 | # Built Visual Studio Code Extensions
134 | *.vsix
--------------------------------------------------------------------------------
/.devcontainer/Dockerfile:
--------------------------------------------------------------------------------
1 | # Specify the Python version and base OS for the container
2 | # VARIANT allows customization of Python version (default: 3.10 on Debian Bullseye)
3 | ARG VARIANT="3.10-bullseye"
4 |
5 | # Use Microsoft's official Python dev container as the base image
6 | FROM mcr.microsoft.com/devcontainers/python:1-${VARIANT}
7 |
8 | # Install system packages as root user before switching to vscode
9 | # - ODBC drivers for SQL Server connectivity
10 | # - GitHub CLI for PR management and git workflows
11 | RUN apt-get update && apt-get install -y \
12 | unixodbc \
13 | unixodbc-dev \
14 | && curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | tee /usr/share/keyrings/githubcli-archive-keyring.gpg > /dev/null \
15 | && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
16 | && apt-get update \
17 | && apt-get install -y gh \
18 | && apt-get clean \
19 | && rm -rf /var/lib/apt/lists/*
20 |
21 | # Switch from root to the vscode user for security and proper file permissions
22 | # The vscode user is pre-configured in the base image with development tools
23 | USER vscode
24 |
25 | # Download and install Poetry package manager for the vscode user
26 | # Poetry manages Python dependencies and virtual environments
27 | RUN curl -sSL https://install.python-poetry.org -o /tmp/install-poetry.py \
28 | && python3 /tmp/install-poetry.py \
29 | && rm /tmp/install-poetry.py
30 |
31 | # Add Poetry's installation directory to the system PATH
32 | # This allows the 'poetry' command to be run from anywhere
33 | ENV PATH="/home/vscode/.local/bin:$PATH"
34 |
35 | # Configure Poetry to create virtual environments inside the project directory
36 | # This creates a .venv folder in your project root instead of Poetry's global cache
37 | # This setting acts as a "gate" - it ensures proper environment setup before shells can run
38 | # Set cache directory to /tmp to enable fast package downloads during build
39 | # while preventing cache bloat in the final Docker image
40 | RUN poetry config virtualenvs.in-project true \
41 | && poetry config cache-dir /tmp/poetry_cache
42 |
43 | # Set the working directory where your project files will be mounted
44 | # This is where VS Code will open and where your code will live
45 | WORKDIR /workspace
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints/commonplayoffseries.md:
--------------------------------------------------------------------------------
1 | # CommonPlayoffSeries
2 | ##### [nba_api/stats/endpoints/commonplayoffseries.py](https://github.com/swar/nba_api/blob/master/src/nba_api/stats/endpoints/commonplayoffseries.py)
3 |
4 | ##### Endpoint URL
5 | >[https://stats.nba.com/stats/commonplayoffseries](https://stats.nba.com/stats/commonplayoffseries)
6 |
7 | ##### Valid URL
8 | >[https://stats.nba.com/stats/commonplayoffseries?LeagueID=00&Season=2019-20&SeriesID=](https://stats.nba.com/stats/commonplayoffseries?LeagueID=00&Season=2019-20&SeriesID=)
9 |
10 | ## Parameters
11 | | API Parameter Name | Python Parameter Variable | Pattern | Required | Nullable |
12 | |-----------------------------------------------------------------------------------------------------------------|---------------------------|:-------:|:--------:|:--------:|
13 | | [_**LeagueID**_](https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md#LeagueID) | league_id | | `Y` | |
14 | | [_**Season**_](https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md#Season) | season | | `Y` | |
15 | | [_**SeriesID**_](https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md#SeriesID) | series_id_nullable | | | `Y` |
16 |
17 | ## Data Sets
18 | #### PlayoffSeries `playoff_series`
19 | ```text
20 | ['GAME_ID', 'HOME_TEAM_ID', 'VISITOR_TEAM_ID', 'SERIES_ID', 'GAME_NUM']
21 | ```
22 |
23 |
24 | ## JSON
25 | ```json
26 | {
27 | "data_sets": {
28 | "PlayoffSeries": [
29 | "GAME_ID",
30 | "HOME_TEAM_ID",
31 | "VISITOR_TEAM_ID",
32 | "SERIES_ID",
33 | "GAME_NUM"
34 | ]
35 | },
36 | "endpoint": "CommonPlayoffSeries",
37 | "last_validated_date": "2020-08-15",
38 | "nullable_parameters": [
39 | "SeriesID"
40 | ],
41 | "parameter_patterns": {
42 | "LeagueID": null,
43 | "Season": null,
44 | "SeriesID": null
45 | },
46 | "parameters": [
47 | "LeagueID",
48 | "Season",
49 | "SeriesID"
50 | ],
51 | "required_parameters": [
52 | "LeagueID",
53 | "Season"
54 | ],
55 | "status": "success"
56 | }
57 | ```
58 |
59 | Last validated 2020-08-16
--------------------------------------------------------------------------------
/tests/unit/test_http.py:
--------------------------------------------------------------------------------
1 | import pytest
2 | import requests
3 | from unittest.mock import Mock
4 | from nba_api.library.http import NBAHTTP
5 | from nba_api.stats.endpoints import AllTimeLeadersGrids
6 |
7 | @pytest.fixture
8 | def mock_session():
9 | session = Mock(spec=requests.Session)
10 | # Mock the get method to return a response-like object
11 | mock_response = Mock()
12 | mock_response.text = '{"resource": "alltimeleadersgrids", "resultSets": {}}'
13 | mock_response.status_code = 200
14 | mock_response.url = "http://stats.nba.com/stats/alltimeleadersgrids"
15 | session.get.return_value = mock_response
16 | return session
17 |
18 | def test_nbahttp_session_management():
19 | # Test default session creation
20 | assert NBAHTTP._session is None
21 | session = NBAHTTP.get_session()
22 | assert isinstance(session, requests.Session)
23 |
24 | # Test setting custom session
25 | custom_session = requests.Session()
26 | NBAHTTP.set_session(custom_session)
27 | assert NBAHTTP.get_session() == custom_session
28 |
29 | def test_endpoint_uses_global_session(mock_session):
30 | # Set up global session
31 | NBAHTTP.set_session(mock_session)
32 |
33 | # Create endpoint and make request
34 | try:
35 | _ = AllTimeLeadersGrids(topx=5)
36 | except KeyError:
37 | # This is expected due to the mock response.
38 | pass
39 |
40 | # Verify the session's get method was called
41 | assert mock_session.get.called
42 |
43 | # Verify the call parameters
44 | call_kwargs = mock_session.get.call_args.kwargs
45 | assert 'params' in call_kwargs
46 | assert 'TopX' in dict(call_kwargs['params'])
47 | assert dict(call_kwargs['params'])['TopX'] == 5
48 |
49 | def test_session_headers_persistence():
50 | # Create session with custom headers
51 | session = requests.Session()
52 | custom_user_agent = 'CustomBot/1.0'
53 | session.headers.update({'User-Agent': custom_user_agent})
54 |
55 | # Set as global session
56 | NBAHTTP.set_session(session)
57 |
58 | # Verify headers are maintained
59 | current_session = NBAHTTP.get_session()
60 | assert current_session.headers['User-Agent'] == custom_user_agent
61 |
62 | @pytest.fixture(autouse=True)
63 | def cleanup():
64 | # Reset session before each test
65 | NBAHTTP._session = None
66 | yield
67 | # Clean up after each test
68 | NBAHTTP._session = None
69 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/gamerotation.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import LeagueID
4 |
5 |
6 | class GameRotation(Endpoint):
7 | endpoint = "gamerotation"
8 | expected_data = {
9 | "AwayTeam": [
10 | "GAME_ID",
11 | "TEAM_ID",
12 | "TEAM_CITY",
13 | "TEAM_NAME",
14 | "PERSON_ID",
15 | "PLAYER_FIRST",
16 | "PLAYER_LAST",
17 | "IN_TIME_REAL",
18 | "OUT_TIME_REAL",
19 | "PLAYER_PTS",
20 | "PT_DIFF",
21 | "USG_PCT",
22 | ],
23 | "HomeTeam": [
24 | "GAME_ID",
25 | "TEAM_ID",
26 | "TEAM_CITY",
27 | "TEAM_NAME",
28 | "PERSON_ID",
29 | "PLAYER_FIRST",
30 | "PLAYER_LAST",
31 | "IN_TIME_REAL",
32 | "OUT_TIME_REAL",
33 | "PLAYER_PTS",
34 | "PT_DIFF",
35 | "USG_PCT",
36 | ],
37 | }
38 |
39 | nba_response = None
40 | data_sets = None
41 | player_stats = None
42 | team_stats = None
43 | headers = None
44 |
45 | def __init__(
46 | self,
47 | game_id,
48 | league_id=LeagueID.default,
49 | proxy=None,
50 | headers=None,
51 | timeout=30,
52 | get_request=True,
53 | ):
54 | self.proxy = proxy
55 | if headers is not None:
56 | self.headers = headers
57 | self.timeout = timeout
58 | self.parameters = {"GameID": game_id, "LeagueID": league_id}
59 | if get_request:
60 | self.get_request()
61 |
62 | def get_request(self):
63 | self.nba_response = NBAStatsHTTP().send_api_request(
64 | endpoint=self.endpoint,
65 | parameters=self.parameters,
66 | proxy=self.proxy,
67 | headers=self.headers,
68 | timeout=self.timeout,
69 | )
70 | self.load_response()
71 |
72 | def load_response(self):
73 | data_sets = self.nba_response.get_data_sets()
74 | self.data_sets = [
75 | Endpoint.DataSet(data=data_set)
76 | for data_set_name, data_set in data_sets.items()
77 | ]
78 | self.away_team = Endpoint.DataSet(data=data_sets["AwayTeam"])
79 | self.home_team = Endpoint.DataSet(data=data_sets["HomeTeam"])
80 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/winprobabilitypbp.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import RunType
4 |
5 |
6 | class WinProbabilityPBP(Endpoint):
7 | endpoint = "winprobabilitypbp"
8 | expected_data = {
9 | "GameInfo": [
10 | "GAME_ID",
11 | "GAME_DATE",
12 | "HOME_TEAM_ID",
13 | "HOME_TEAM_ABR",
14 | "HOME_TEAM_PTS",
15 | "VISITOR_TEAM_ID",
16 | "VISITOR_TEAM_ABR",
17 | "VISITOR_TEAM_PTS",
18 | ],
19 | "WinProbPBP": [
20 | "GAME_ID",
21 | "EVENT_NUM",
22 | "HOME_PCT",
23 | "VISITOR_PCT",
24 | "HOME_PTS",
25 | "VISITOR_PTS",
26 | "HOME_SCORE_MARGIN",
27 | "PERIOD",
28 | "SECONDS_REMAINING",
29 | "HOME_POSS_IND",
30 | "HOME_G",
31 | "DESCRIPTION",
32 | "LOCATION",
33 | "PCTIMESTRING",
34 | "ISVISIBLE",
35 | ],
36 | }
37 |
38 | nba_response = None
39 | data_sets = None
40 | player_stats = None
41 | team_stats = None
42 | headers = None
43 |
44 | def __init__(
45 | self,
46 | game_id,
47 | run_type=RunType.default,
48 | proxy=None,
49 | headers=None,
50 | timeout=30,
51 | get_request=True,
52 | ):
53 | self.proxy = proxy
54 | if headers is not None:
55 | self.headers = headers
56 | self.timeout = timeout
57 | self.parameters = {"GameID": game_id, "RunType": run_type}
58 | if get_request:
59 | self.get_request()
60 |
61 | def get_request(self):
62 | self.nba_response = NBAStatsHTTP().send_api_request(
63 | endpoint=self.endpoint,
64 | parameters=self.parameters,
65 | proxy=self.proxy,
66 | headers=self.headers,
67 | timeout=self.timeout,
68 | )
69 | self.load_response()
70 |
71 | def load_response(self):
72 | data_sets = self.nba_response.get_data_sets()
73 | self.data_sets = [
74 | Endpoint.DataSet(data=data_set)
75 | for data_set_name, data_set in data_sets.items()
76 | ]
77 | self.game_info = Endpoint.DataSet(data=data_sets["GameInfo"])
78 | self.win_prob_p_bp = Endpoint.DataSet(data=data_sets["WinProbPBP"])
79 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/leaguedashptstats_output.md:
--------------------------------------------------------------------------------
1 | LeagueDashPtStats:
2 |
3 | | TEAM_ID | TEAM_ABBREVIATION | TEAM_NAME | GP | W | L | MIN | DIST_FEET | DIST_MILES | DIST_MILES_OFF | DIST_MILES_DEF | AVG_SPEED | AVG_SPEED_OFF | AVG_SPEED_DEF |
4 | |-----------:|:--------------------|:----------------------|-----:|----:|----:|------:|------------:|-------------:|-----------------:|-----------------:|------------:|----------------:|----------------:|
5 | | 1610612737 | ATL | Atlanta Hawks | 82 | 36 | 46 | 19855 | 7789797 | 1475.3 | 785.4 | 689.9 | 4.19 | 4.5 | 3.89 |
6 | | 1610612738 | BOS | Boston Celtics | 81 | 63 | 18 | 19590 | 7527507 | 1425.7 | 760.1 | 665.5 | 4.08 | 4.34 | 3.81 |
7 | | 1610612751 | BKN | Brooklyn Nets | 79 | 32 | 47 | 19085 | 7557797 | 1431.4 | 780.7 | 650.7 | 4.2 | 4.51 | 3.87 |
8 | | 1610612766 | CHA | Charlotte Hornets | 81 | 20 | 61 | 19490 | 7939324 | 1503.7 | 821.5 | 682.2 | 4.31 | 4.67 | 3.95 |
9 | | 1610612741 | CHI | Chicago Bulls | 81 | 39 | 42 | 19740 | 7650693 | 1449 | 761.1 | 687.9 | 4.16 | 4.48 | 3.86 |
10 | | 1610612739 | CLE | Cleveland Cavaliers | 82 | 48 | 34 | 19805 | 7860869 | 1488.8 | 801.5 | 687.3 | 4.2 | 4.54 | 3.87 |
11 | | 1610612742 | DAL | Dallas Mavericks | 81 | 49 | 32 | 19465 | 7620769 | 1443.3 | 761.6 | 681.7 | 4.17 | 4.43 | 3.91 |
12 | | 1610612743 | DEN | Denver Nuggets | 80 | 55 | 25 | 19225 | 7393005 | 1400.2 | 755.4 | 644.8 | 4.08 | 4.33 | 3.81 |
13 | | 1610612765 | DET | Detroit Pistons | 81 | 14 | 67 | 19515 | 7851729 | 1487.1 | 799.3 | 687.8 | 4.27 | 4.63 | 3.91 |
14 | | 1610612744 | GSW | Golden State Warriors | 81 | 46 | 35 | 19590 | 7782108 | 1473.9 | 807.9 | 666 | 4.26 | 4.66 | 3.86 |
--------------------------------------------------------------------------------
/tests/unit/stats/endpoints/test_teamgamelog.py:
--------------------------------------------------------------------------------
1 | """Unit tests for TeamGameLog endpoint."""
2 |
3 | import pytest
4 |
5 | from nba_api.stats.endpoints import TeamGameLog
6 |
7 |
8 | class TestTeamGameLogInitialization:
9 | """Test TeamGameLog initialization."""
10 |
11 | def test_endpoint_initialization_without_request(self):
12 | """Test endpoint initializes without making HTTP request."""
13 | endpoint = TeamGameLog(
14 | team_id='1610612747',
15 | season='2023-24',
16 | season_type_all_star='Regular Season',
17 | get_request=False
18 | )
19 |
20 | assert endpoint.parameters["TeamID"] == '1610612747'
21 | assert endpoint.parameters["Season"] == '2023-24'
22 | assert endpoint.parameters["SeasonType"] == 'Regular Season'
23 | assert endpoint.endpoint == "teamgamelog"
24 |
25 | def test_required_parameter_team_id(self):
26 | """Test that team_id is required."""
27 | with pytest.raises(TypeError):
28 | TeamGameLog(get_request=False)
29 |
30 | def test_optional_date_parameters(self):
31 | """Test date filtering parameters."""
32 | endpoint = TeamGameLog(
33 | team_id='1610612747',
34 | date_from_nullable='01/01/2024',
35 | date_to_nullable='01/31/2024',
36 | get_request=False
37 | )
38 |
39 | assert endpoint.parameters["DateFrom"] == '01/01/2024'
40 | assert endpoint.parameters["DateTo"] == '01/31/2024'
41 |
42 | def test_dataset_attributes_initialized(self):
43 | """Test that dataset attributes are initialized in __init__."""
44 | endpoint = TeamGameLog(
45 | team_id='1610612747',
46 | get_request=False
47 | )
48 |
49 | # Dataset attribute should be None before request
50 | assert endpoint.team_game_log is None
51 |
52 | def test_expected_data_structure(self):
53 | """Test that expected_data has required fields."""
54 | assert "TeamGameLog" in TeamGameLog.expected_data
55 | expected_fields = TeamGameLog.expected_data["TeamGameLog"]
56 |
57 | # Check for key fields
58 | assert "Team_ID" in expected_fields
59 | assert "Game_ID" in expected_fields
60 | assert "GAME_DATE" in expected_fields
61 | assert "MATCHUP" in expected_fields
62 | assert "WL" in expected_fields
63 | assert "PTS" in expected_fields
64 |
--------------------------------------------------------------------------------
/tests/integration/test_stats_library_playbyplayregex.py:
--------------------------------------------------------------------------------
1 | import pytest
2 | import datetime
3 | import time
4 | from nba_api.stats.endpoints import ScoreboardV2
5 | from nba_api.stats.endpoints import PlayByPlay
6 | from nba_api.stats.library.parameters import LeagueID
7 | from nba_api.stats.library.eventmsgtype import EventMsgType
8 | from nba_api.stats.library.playbyplayregex import eventmsgtype_to_re
9 |
10 |
11 | def pytest_generate_tests(metafunc):
12 | if "game" in metafunc.fixturenames and "play" in metafunc.fixturenames:
13 | metafunc.parametrize(
14 | "game, play",
15 | [
16 | (game_id, play_by_play)
17 | for game_id in get_game_ids()
18 | for play_by_play in get_play_by_play(game_id)
19 | ],
20 | )
21 |
22 |
23 | def get_game_ids():
24 | gamefinder = ScoreboardV2(
25 | league_id=LeagueID.nba, day_offset=-1, game_date=datetime.datetime.now()
26 | )
27 |
28 | games_dict = gamefinder.get_normalized_dict()
29 | games = []
30 | for game in games_dict["GameHeader"]:
31 | games.append(game["GAME_ID"])
32 |
33 | return games
34 |
35 |
36 | def get_play_by_play(game_id):
37 | # Delay briefly to prevent throttling
38 | time.sleep(0.600)
39 | return PlayByPlay(game_id).get_normalized_dict()["PlayByPlay"]
40 |
41 |
42 | @pytest.fixture()
43 | def game(request):
44 | return request.param
45 |
46 |
47 | @pytest.fixture()
48 | def play(request):
49 | return request.param
50 |
51 |
52 | def test_play(game, play):
53 | for count in range(0, 1):
54 | dict_patterns = eventmsgtype_to_re[EventMsgType(play["EVENTMSGTYPE"])]
55 | description = (
56 | play["HOMEDESCRIPTION"] if count == 0 else play["VISITORDESCRIPTION"]
57 | )
58 |
59 | # Validate description
60 | if description is not None:
61 | match = False
62 | for pattern in dict_patterns:
63 | if pattern.match(description):
64 | match = True
65 |
66 | if match == False:
67 | msg = "EVENTMSGTYPE {eventmsgtype}: [{description}]\n\tAttempted Patterns\n".format(
68 | eventmsgtype=play["EVENTMSGTYPE"], description=description
69 | )
70 | for pattern in dict_patterns:
71 | msg += "\t\t{pattern}\n".format(pattern=pattern.pattern)
72 |
73 | assert False, msg
74 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints/franchiseleaders.md:
--------------------------------------------------------------------------------
1 | # FranchiseLeaders
2 | ##### [nba_api/stats/endpoints/franchiseleaders.py](https://github.com/swar/nba_api/blob/master/src/nba_api/stats/endpoints/franchiseleaders.py)
3 |
4 | ##### Endpoint URL
5 | >[https://stats.nba.com/stats/franchiseleaders](https://stats.nba.com/stats/franchiseleaders)
6 |
7 | ##### Valid URL
8 | >[https://stats.nba.com/stats/franchiseleaders?LeagueID=&TeamID=1610612739](https://stats.nba.com/stats/franchiseleaders?LeagueID=&TeamID=1610612739)
9 |
10 | ## Parameters
11 | | API Parameter Name | Python Parameter Variable | Pattern | Required | Nullable |
12 | |-----------------------------------------------------------------------------------------------------------------|---------------------------|:-------:|:--------:|:--------:|
13 | | [_**TeamID**_](https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md#TeamID) | team_id | | `Y` | |
14 | | [_**LeagueID**_](https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md#LeagueID) | league_id_nullable | | | `Y` |
15 |
16 | ## Data Sets
17 | #### FranchiseLeaders `franchise_leaders`
18 | ```text
19 | ['TEAM_ID', 'PTS', 'PTS_PERSON_ID', 'PTS_PLAYER', 'AST', 'AST_PERSON_ID', 'AST_PLAYER', 'REB', 'REB_PERSON_ID', 'REB_PLAYER', 'BLK', 'BLK_PERSON_ID', 'BLK_PLAYER', 'STL', 'STL_PERSON_ID', 'STL_PLAYER']
20 | ```
21 |
22 |
23 | ## JSON
24 | ```json
25 | {
26 | "data_sets": {
27 | "FranchiseLeaders": [
28 | "TEAM_ID",
29 | "PTS",
30 | "PTS_PERSON_ID",
31 | "PTS_PLAYER",
32 | "AST",
33 | "AST_PERSON_ID",
34 | "AST_PLAYER",
35 | "REB",
36 | "REB_PERSON_ID",
37 | "REB_PLAYER",
38 | "BLK",
39 | "BLK_PERSON_ID",
40 | "BLK_PLAYER",
41 | "STL",
42 | "STL_PERSON_ID",
43 | "STL_PLAYER"
44 | ]
45 | },
46 | "endpoint": "FranchiseLeaders",
47 | "last_validated_date": "2020-08-15",
48 | "nullable_parameters": [
49 | "LeagueID"
50 | ],
51 | "parameter_patterns": {
52 | "LeagueID": null,
53 | "TeamID": null
54 | },
55 | "parameters": [
56 | "LeagueID",
57 | "TeamID"
58 | ],
59 | "required_parameters": [
60 | "TeamID"
61 | ],
62 | "status": "success"
63 | }
64 | ```
65 |
66 | Last validated 2020-08-16
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/playernextngames.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import (
4 | NumberOfGames,
5 | SeasonAll,
6 | SeasonTypeAllStar,
7 | LeagueIDNullable,
8 | )
9 |
10 |
11 | class PlayerNextNGames(Endpoint):
12 | endpoint = "playernextngames"
13 | expected_data = {
14 | "NextNGames": [
15 | "GAME_ID",
16 | "GAME_DATE",
17 | "HOME_TEAM_ID",
18 | "VISITOR_TEAM_ID",
19 | "HOME_TEAM_NAME",
20 | "VISITOR_TEAM_NAME",
21 | "HOME_TEAM_ABBREVIATION",
22 | "VISITOR_TEAM_ABBREVIATION",
23 | "HOME_TEAM_NICKNAME",
24 | "VISITOR_TEAM_NICKNAME",
25 | "GAME_TIME",
26 | "HOME_WL",
27 | "VISITOR_WL",
28 | ]
29 | }
30 |
31 | nba_response = None
32 | data_sets = None
33 | player_stats = None
34 | team_stats = None
35 | headers = None
36 |
37 | def __init__(
38 | self,
39 | player_id,
40 | number_of_games=NumberOfGames.default,
41 | season_all=SeasonAll.default,
42 | season_type_all_star=SeasonTypeAllStar.default,
43 | league_id_nullable=LeagueIDNullable.default,
44 | proxy=None,
45 | headers=None,
46 | timeout=30,
47 | get_request=True,
48 | ):
49 | self.proxy = proxy
50 | if headers is not None:
51 | self.headers = headers
52 | self.timeout = timeout
53 | self.parameters = {
54 | "PlayerID": player_id,
55 | "NumberOfGames": number_of_games,
56 | "Season": season_all,
57 | "SeasonType": season_type_all_star,
58 | "LeagueID": league_id_nullable,
59 | }
60 | if get_request:
61 | self.get_request()
62 |
63 | def get_request(self):
64 | self.nba_response = NBAStatsHTTP().send_api_request(
65 | endpoint=self.endpoint,
66 | parameters=self.parameters,
67 | proxy=self.proxy,
68 | headers=self.headers,
69 | timeout=self.timeout,
70 | )
71 | self.load_response()
72 |
73 | def load_response(self):
74 | data_sets = self.nba_response.get_data_sets()
75 | self.data_sets = [
76 | Endpoint.DataSet(data=data_set)
77 | for data_set_name, data_set in data_sets.items()
78 | ]
79 | self.next_n_games = Endpoint.DataSet(data=data_sets["NextNGames"])
80 |
--------------------------------------------------------------------------------
/tests/integration/data/teamgamelogs.py:
--------------------------------------------------------------------------------
1 | """
2 | Test data for TeamGameLogs endpoint.
3 |
4 | GitHub Issues:
5 | - Endpoint was retired in v1.11.0 but is now working again (restored in v1.11.3)
6 |
7 | Key Differences from TeamGameLog:
8 | - TeamGameLog: Single team, required team_id parameter
9 | - TeamGameLogs: Multiple teams, optional team_id_nullable parameter
10 | - TeamGameLogs: Includes rank fields (_RANK) for all statistics
11 | - TeamGameLogs: More filtering options (conference, division, measure type)
12 |
13 | Expected response formats:
14 | - String: "success" | "has_data" | "empty" | "error"
15 | - Dict: {"status": "success", "min_rows": 1, "max_rows": 100}
16 | """
17 |
18 | # Endpoint class name
19 | ENDPOINT_CLASS = "TeamGameLogs"
20 |
21 | # Test cases
22 | TEST_CASES = [
23 | {
24 | "description": "Lakers 2023-24 regular season",
25 | "params": {
26 | "team_id_nullable": "1610612747",
27 | "season_nullable": "2023-24",
28 | "season_type_nullable": "Regular Season",
29 | },
30 | "expected": {
31 | "status": "has_data",
32 | "validate_structure": True, # Enable strict validation
33 | },
34 | },
35 | {
36 | "description": "All teams - last game only",
37 | "params": {
38 | "season_nullable": "2024-25",
39 | "season_type_nullable": "Regular Season",
40 | "last_n_games_nullable": "1",
41 | },
42 | "expected": "has_data", # Should return ~30 games (one per team)
43 | },
44 | {
45 | "description": "Home games only",
46 | "params": {
47 | "team_id_nullable": "1610612747",
48 | "season_nullable": "2023-24",
49 | "location_nullable": "Home",
50 | },
51 | "expected": "has_data", # Should return ~41 home games
52 | },
53 | {
54 | "description": "Wins only",
55 | "params": {
56 | "team_id_nullable": "1610612747",
57 | "season_nullable": "2023-24",
58 | "outcome_nullable": "W",
59 | },
60 | "expected": "has_data", # Should return only winning games
61 | },
62 | {
63 | "description": "Eastern Conference opponents",
64 | "params": {
65 | "team_id_nullable": "1610612747", # Lakers (West)
66 | "season_nullable": "2023-24",
67 | "vs_conference_nullable": "East",
68 | },
69 | "expected": "has_data", # Games vs Eastern Conference
70 | },
71 | ]
72 |
--------------------------------------------------------------------------------
/tests/unit/stats/endpoints/data/teamdashlineups.py:
--------------------------------------------------------------------------------
1 | """Test data for TeamDashLineups endpoint.
2 |
3 | Contains minimal fixture representing API response structure.
4 |
5 | Full API response available in:
6 | docs/nba_api/stats/endpoints/responses/teamdashlineups.json
7 | """
8 |
9 | TEAMDASHLINEUPS_SAMPLE = {
10 | "resource": "teamdashlineups",
11 | "parameters": {
12 | "TeamID": 1610612739,
13 | "Season": "2024-25",
14 | "SeasonType": "Regular Season",
15 | "GroupQuantity": 5,
16 | "MeasureType": "Base",
17 | "PerMode": "Totals",
18 | "PlusMinus": "N",
19 | "PaceAdjust": "N",
20 | "Rank": "N",
21 | "LastNGames": 0,
22 | "Month": 0,
23 | "OpponentTeamID": 0,
24 | "Period": 0,
25 | "LeagueID": "00"
26 | },
27 | "resultSets": [
28 | {
29 | "name": "Lineups",
30 | "headers": [
31 | "GROUP_SET",
32 | "GROUP_ID",
33 | "GROUP_NAME",
34 | "GP",
35 | "W",
36 | "L",
37 | "W_PCT",
38 | "MIN",
39 | "FGM",
40 | "FGA",
41 | "FG_PCT",
42 | ],
43 | "rowSet": [
44 | [
45 | "5 Man",
46 | 123456,
47 | "Player1 - Player2 - Player3 - Player4 - Player5",
48 | 10,
49 | 7,
50 | 3,
51 | 0.700,
52 | 150.5,
53 | 55,
54 | 120,
55 | 0.458,
56 | ]
57 | ]
58 | },
59 | {
60 | "name": "Overall",
61 | "headers": [
62 | "GROUP_SET",
63 | "GROUP_VALUE",
64 | "TEAM_ID",
65 | "TEAM_ABBREVIATION",
66 | "TEAM_NAME",
67 | "GP",
68 | "W",
69 | "L",
70 | "W_PCT",
71 | ],
72 | "rowSet": [
73 | [
74 | "Overall",
75 | "Overall",
76 | 1610612739,
77 | "CLE",
78 | "Cleveland Cavaliers",
79 | 82,
80 | 50,
81 | 32,
82 | 0.610,
83 | ]
84 | ]
85 | }
86 | ]
87 | }
88 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints/draftcombinedrillresults.md:
--------------------------------------------------------------------------------
1 | # DraftCombineDrillResults
2 | ##### [nba_api/stats/endpoints/draftcombinedrillresults.py](https://github.com/swar/nba_api/blob/master/src/nba_api/stats/endpoints/draftcombinedrillresults.py)
3 |
4 | ##### Endpoint URL
5 | >[https://stats.nba.com/stats/draftcombinedrillresults](https://stats.nba.com/stats/draftcombinedrillresults)
6 |
7 | ##### Valid URL
8 | >[https://stats.nba.com/stats/draftcombinedrillresults?LeagueID=00&SeasonYear=2019](https://stats.nba.com/stats/draftcombinedrillresults?LeagueID=00&SeasonYear=2019)
9 |
10 | ## Parameters
11 | | API Parameter Name | Python Parameter Variable | Pattern | Required | Nullable |
12 | |---------------------------------------------------------------------------------------------------------------------|---------------------------|:-------:|:--------:|:--------:|
13 | | [_**LeagueID**_](https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md#LeagueID) | league_id | | `Y` | |
14 | | [_**SeasonYear**_](https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md#SeasonYear) | season_year | | `Y` | |
15 |
16 | ## Data Sets
17 | #### Results `results`
18 | ```text
19 | ['TEMP_PLAYER_ID', 'PLAYER_ID', 'FIRST_NAME', 'LAST_NAME', 'PLAYER_NAME', 'POSITION', 'STANDING_VERTICAL_LEAP', 'MAX_VERTICAL_LEAP', 'LANE_AGILITY_TIME', 'MODIFIED_LANE_AGILITY_TIME', 'THREE_QUARTER_SPRINT', 'BENCH_PRESS']
20 | ```
21 |
22 |
23 | ## JSON
24 | ```json
25 | {
26 | "data_sets": {
27 | "Results": [
28 | "TEMP_PLAYER_ID",
29 | "PLAYER_ID",
30 | "FIRST_NAME",
31 | "LAST_NAME",
32 | "PLAYER_NAME",
33 | "POSITION",
34 | "STANDING_VERTICAL_LEAP",
35 | "MAX_VERTICAL_LEAP",
36 | "LANE_AGILITY_TIME",
37 | "MODIFIED_LANE_AGILITY_TIME",
38 | "THREE_QUARTER_SPRINT",
39 | "BENCH_PRESS"
40 | ]
41 | },
42 | "endpoint": "DraftCombineDrillResults",
43 | "last_validated_date": "2020-08-15",
44 | "nullable_parameters": [],
45 | "parameter_patterns": {
46 | "LeagueID": null,
47 | "SeasonYear": null
48 | },
49 | "parameters": [
50 | "LeagueID",
51 | "SeasonYear"
52 | ],
53 | "required_parameters": [
54 | "LeagueID",
55 | "SeasonYear"
56 | ],
57 | "status": "success"
58 | }
59 | ```
60 |
61 | Last validated 2020-08-16
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints/videostatus.md:
--------------------------------------------------------------------------------
1 | # VideoStatus
2 | ##### [nba_api/stats/endpoints/videostatus.py](https://github.com/swar/nba_api/blob/master/src/nba_api/stats/endpoints/videostatus.py)
3 |
4 | ##### Endpoint URL
5 | >[https://stats.nba.com/stats/videostatus](https://stats.nba.com/stats/videostatus)
6 |
7 | ##### Valid URL
8 | >[https://stats.nba.com/stats/videostatus?GameDate=2020-08-16&LeagueID=00](https://stats.nba.com/stats/videostatus?GameDate=2020-08-16&LeagueID=00)
9 |
10 | ## Parameters
11 | | API Parameter Name | Python Parameter Variable | Pattern | Required | Nullable |
12 | |-----------------------------------------------------------------------------------------------------------------|---------------------------|:---------:|:--------:|:--------:|
13 | | [_**GameDate**_](https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md#GameDate) | game_date | | `Y` | |
14 | | [_**LeagueID**_](https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md#LeagueID) | league_id | `^\d{2}$` | `Y` | |
15 |
16 | ## Data Sets
17 | #### VideoStatus `video_status`
18 | ```text
19 | ['GAME_ID', 'GAME_DATE', 'VISITOR_TEAM_ID', 'VISITOR_TEAM_CITY', 'VISITOR_TEAM_NAME', 'VISITOR_TEAM_ABBREVIATION', 'HOME_TEAM_ID', 'HOME_TEAM_CITY', 'HOME_TEAM_NAME', 'HOME_TEAM_ABBREVIATION', 'GAME_STATUS', 'GAME_STATUS_TEXT', 'IS_AVAILABLE', 'PT_XYZ_AVAILABLE']
20 | ```
21 |
22 |
23 | ## JSON
24 | ```json
25 | {
26 | "data_sets": {
27 | "VideoStatus": [
28 | "GAME_ID",
29 | "GAME_DATE",
30 | "VISITOR_TEAM_ID",
31 | "VISITOR_TEAM_CITY",
32 | "VISITOR_TEAM_NAME",
33 | "VISITOR_TEAM_ABBREVIATION",
34 | "HOME_TEAM_ID",
35 | "HOME_TEAM_CITY",
36 | "HOME_TEAM_NAME",
37 | "HOME_TEAM_ABBREVIATION",
38 | "GAME_STATUS",
39 | "GAME_STATUS_TEXT",
40 | "IS_AVAILABLE",
41 | "PT_XYZ_AVAILABLE"
42 | ]
43 | },
44 | "endpoint": "VideoStatus",
45 | "last_validated_date": "2020-08-15",
46 | "nullable_parameters": [],
47 | "parameter_patterns": {
48 | "GameDate": null,
49 | "LeagueID": "^\\d{2}$"
50 | },
51 | "parameters": [
52 | "GameDate",
53 | "LeagueID"
54 | ],
55 | "required_parameters": [
56 | "GameDate",
57 | "LeagueID"
58 | ],
59 | "status": "success"
60 | }
61 | ```
62 |
63 | Last validated 2020-08-16
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/franchisehistory.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import LeagueID
4 |
5 |
6 | class FranchiseHistory(Endpoint):
7 | endpoint = "franchisehistory"
8 | expected_data = {
9 | "DefunctTeams": [
10 | "LEAGUE_ID",
11 | "TEAM_ID",
12 | "TEAM_CITY",
13 | "TEAM_NAME",
14 | "START_YEAR",
15 | "END_YEAR",
16 | "YEARS",
17 | "GAMES",
18 | "WINS",
19 | "LOSSES",
20 | "WIN_PCT",
21 | "PO_APPEARANCES",
22 | "DIV_TITLES",
23 | "CONF_TITLES",
24 | "LEAGUE_TITLES",
25 | ],
26 | "FranchiseHistory": [
27 | "LEAGUE_ID",
28 | "TEAM_ID",
29 | "TEAM_CITY",
30 | "TEAM_NAME",
31 | "START_YEAR",
32 | "END_YEAR",
33 | "YEARS",
34 | "GAMES",
35 | "WINS",
36 | "LOSSES",
37 | "WIN_PCT",
38 | "PO_APPEARANCES",
39 | "DIV_TITLES",
40 | "CONF_TITLES",
41 | "LEAGUE_TITLES",
42 | ],
43 | }
44 |
45 | nba_response = None
46 | data_sets = None
47 | player_stats = None
48 | team_stats = None
49 | headers = None
50 |
51 | def __init__(
52 | self,
53 | league_id=LeagueID.default,
54 | proxy=None,
55 | headers=None,
56 | timeout=30,
57 | get_request=True,
58 | ):
59 | self.proxy = proxy
60 | if headers is not None:
61 | self.headers = headers
62 | self.timeout = timeout
63 | self.parameters = {"LeagueID": league_id}
64 | if get_request:
65 | self.get_request()
66 |
67 | def get_request(self):
68 | self.nba_response = NBAStatsHTTP().send_api_request(
69 | endpoint=self.endpoint,
70 | parameters=self.parameters,
71 | proxy=self.proxy,
72 | headers=self.headers,
73 | timeout=self.timeout,
74 | )
75 | self.load_response()
76 |
77 | def load_response(self):
78 | data_sets = self.nba_response.get_data_sets()
79 | self.data_sets = [
80 | Endpoint.DataSet(data=data_set)
81 | for data_set_name, data_set in data_sets.items()
82 | ]
83 | self.defunct_teams = Endpoint.DataSet(data=data_sets["DefunctTeams"])
84 | self.franchise_history = Endpoint.DataSet(data=data_sets["FranchiseHistory"])
85 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/glalumboxscoresimilarityscore.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import LeagueID, SeasonYear, SeasonType
4 |
5 |
6 | class GLAlumBoxScoreSimilarityScore(Endpoint):
7 | endpoint = "glalumboxscoresimilarityscore"
8 | expected_data = {
9 | "GLeagueAlumBoxScoreSimilarityScores": [
10 | "PERSON_2_ID",
11 | "PERSON_2",
12 | "TEAM_ID",
13 | "SIMILARITY_SCORE",
14 | ]
15 | }
16 |
17 | nba_response = None
18 | data_sets = None
19 | player_stats = None
20 | team_stats = None
21 | headers = None
22 |
23 | def __init__(
24 | self,
25 | person2_id,
26 | person1_id,
27 | person1_league_id=LeagueID.default,
28 | person1_season_year=SeasonYear.default,
29 | person1_season_type=SeasonType.default,
30 | person2_league_id=LeagueID.default,
31 | person2_season_year=SeasonYear.default,
32 | person2_season_type=SeasonType.default,
33 | proxy=None,
34 | headers=None,
35 | timeout=30,
36 | get_request=True,
37 | ):
38 | self.proxy = proxy
39 | if headers is not None:
40 | self.headers = headers
41 | self.timeout = timeout
42 | self.parameters = {
43 | "Person2Id": person2_id,
44 | "Person1Id": person1_id,
45 | "Person1LeagueId": person1_league_id,
46 | "Person1Season": person1_season_year,
47 | "Person1SeasonType": person1_season_type,
48 | "Person2LeagueId": person2_league_id,
49 | "Person2Season": person2_season_year,
50 | "Person2SeasonType": person2_season_type,
51 | }
52 | if get_request:
53 | self.get_request()
54 |
55 | def get_request(self):
56 | self.nba_response = NBAStatsHTTP().send_api_request(
57 | endpoint=self.endpoint,
58 | parameters=self.parameters,
59 | proxy=self.proxy,
60 | headers=self.headers,
61 | timeout=self.timeout,
62 | )
63 | self.load_response()
64 |
65 | def load_response(self):
66 | data_sets = self.nba_response.get_data_sets()
67 | self.data_sets = [
68 | Endpoint.DataSet(data=data_set)
69 | for data_set_name, data_set in data_sets.items()
70 | ]
71 | self.g_league_alum_box_score_similarity_scores = Endpoint.DataSet(
72 | data=data_sets["GLeagueAlumBoxScoreSimilarityScores"]
73 | )
74 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/playbyplayv3.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import EndPeriod, StartPeriod
4 |
5 |
6 | class PlayByPlayV3(Endpoint):
7 | endpoint = "playbyplayv3"
8 | expected_data = {
9 | "AvailableVideo": ["videoAvailable"],
10 | "PlayByPlay": [
11 | "gameId",
12 | "actionNumber",
13 | "clock",
14 | "period",
15 | "teamId",
16 | "teamTricode",
17 | "personId",
18 | "playerName",
19 | "playerNameI",
20 | "xLegacy",
21 | "yLegacy",
22 | "shotDistance",
23 | "shotResult",
24 | "isFieldGoal",
25 | "scoreHome",
26 | "scoreAway",
27 | "pointsTotal",
28 | "location",
29 | "description",
30 | "actionType",
31 | "subType",
32 | "videoAvailable",
33 | "actionId",
34 | ],
35 | }
36 |
37 | nba_response = None
38 | data_sets = None
39 | player_stats = None
40 | team_stats = None
41 | headers = None
42 |
43 | def __init__(
44 | self,
45 | game_id,
46 | end_period=EndPeriod.default,
47 | start_period=StartPeriod.default,
48 | proxy=None,
49 | headers=None,
50 | timeout=30,
51 | get_request=True,
52 | ):
53 | self.proxy = proxy
54 | if headers is not None:
55 | self.headers = headers
56 | self.timeout = timeout
57 | self.parameters = {
58 | "GameID": game_id,
59 | "EndPeriod": end_period,
60 | "StartPeriod": start_period,
61 | }
62 | if get_request:
63 | self.get_request()
64 |
65 | def get_request(self):
66 | self.nba_response = NBAStatsHTTP().send_api_request(
67 | endpoint=self.endpoint,
68 | parameters=self.parameters,
69 | proxy=self.proxy,
70 | headers=self.headers,
71 | timeout=self.timeout,
72 | )
73 | self.load_response()
74 |
75 | def load_response(self):
76 | data_sets = self.nba_response.get_data_sets(self.endpoint)
77 | self.data_sets = [
78 | Endpoint.DataSet(data=data_set)
79 | for data_set_name, data_set in data_sets.items()
80 | ]
81 | self.available_video = Endpoint.DataSet(data=data_sets["AvailableVideo"])
82 | self.play_by_play = Endpoint.DataSet(data=data_sets["PlayByPlay"])
83 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/cumestatsplayergames.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import (
4 | LeagueID,
5 | Season,
6 | SeasonTypeAllStar,
7 | LocationNullable,
8 | OutcomeNullable,
9 | ConferenceNullable,
10 | DivisionNullable,
11 | )
12 |
13 |
14 | class CumeStatsPlayerGames(Endpoint):
15 | endpoint = "cumestatsplayergames"
16 | expected_data = {"CumeStatsPlayerGames": ["MATCHUP", "GAME_ID"]}
17 |
18 | nba_response = None
19 | data_sets = None
20 | player_stats = None
21 | team_stats = None
22 | headers = None
23 |
24 | def __init__(
25 | self,
26 | player_id,
27 | league_id=LeagueID.default,
28 | season=Season.default,
29 | season_type_all_star=SeasonTypeAllStar.default,
30 | location_nullable=LocationNullable.default,
31 | outcome_nullable=OutcomeNullable.default,
32 | vs_conference_nullable=ConferenceNullable.default,
33 | vs_division_nullable=DivisionNullable.default,
34 | vs_team_id_nullable="",
35 | proxy=None,
36 | headers=None,
37 | timeout=30,
38 | get_request=True,
39 | ):
40 | self.proxy = proxy
41 | if headers is not None:
42 | self.headers = headers
43 | self.timeout = timeout
44 | self.parameters = {
45 | "PlayerID": player_id,
46 | "LeagueID": league_id,
47 | "Season": season,
48 | "SeasonType": season_type_all_star,
49 | "Location": location_nullable,
50 | "Outcome": outcome_nullable,
51 | "VsConference": vs_conference_nullable,
52 | "VsDivision": vs_division_nullable,
53 | "VsTeamID": vs_team_id_nullable,
54 | }
55 | if get_request:
56 | self.get_request()
57 |
58 | def get_request(self):
59 | self.nba_response = NBAStatsHTTP().send_api_request(
60 | endpoint=self.endpoint,
61 | parameters=self.parameters,
62 | proxy=self.proxy,
63 | headers=self.headers,
64 | timeout=self.timeout,
65 | )
66 | self.load_response()
67 |
68 | def load_response(self):
69 | data_sets = self.nba_response.get_data_sets()
70 | self.data_sets = [
71 | Endpoint.DataSet(data=data_set)
72 | for data_set_name, data_set in data_sets.items()
73 | ]
74 | self.cume_stats_player_games = Endpoint.DataSet(
75 | data=data_sets["CumeStatsPlayerGames"]
76 | )
77 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/playerawards_output.md:
--------------------------------------------------------------------------------
1 | PlayerAwards:
2 |
3 | | PERSON_ID | FIRST_NAME | LAST_NAME | TEAM | DESCRIPTION | ALL_NBA_TEAM_NUMBER | SEASON | MONTH | WEEK | CONFERENCE | TYPE | SUBTYPE1 | SUBTYPE2 | SUBTYPE3 |
4 | |------------:|:-------------|:------------|:---------------|:------------------------|:----------------------|:---------|:---------|:--------------------|:-------------|:-------|:-----------|:-----------|:-----------|
5 | | 1628369 | Jayson | Tatum | Boston Celtics | All-Rookie Team | 1 | 2017-18 | | | East | Award | Kia Motors | KIART | |
6 | | 1628369 | Jayson | Tatum | Boston Celtics | All-NBA | 3 | 2019-20 | | | East | Award | Kia Motors | KIANT | |
7 | | 1628369 | Jayson | Tatum | Boston Celtics | NBA Player of the Month | | 2019-20 | 2/1/2020 | | East | Award | Kia Motors | KIPMO | |
8 | | 1628369 | Jayson | Tatum | Boston Celtics | NBA Player of the Week | | 2019-20 | | 2020-02-03T00:00:00 | East | Award | Kia Motors | KIPWK | |
9 | | 1628369 | Jayson | Tatum | Boston Celtics | NBA Player of the Week | | 2020-21 | | 2021-01-04T00:00:00 | East | Award | Kia Motors | KIPWK | |
10 | | 1628369 | Jayson | Tatum | Boston Celtics | NBA Player of the Week | | 2020-21 | | 2021-04-05T00:00:00 | East | Award | Kia Motors | KIPWK | |
11 | | 1628369 | Jayson | Tatum | Boston Celtics | NBA Player of the Week | | 2020-21 | | 2021-04-26T00:00:00 | East | Award | Kia Motors | KIPWK | |
12 | | 1628369 | Jayson | Tatum | Boston Celtics | NBA Rookie of the Month | | 2017-18 | 2/1/2018 | 1900-01-01T12:00:00 | East | Award | Kia Motors | KIRMO | |
13 | | 1628369 | Jayson | Tatum | Boston Celtics | NBA Player of the Week | | 2021-22 | | 2021-12-13T00:00:00 | East | Award | Kia Motors | KIPWK | |
14 | | 1628369 | Jayson | Tatum | Boston Celtics | NBA Player of the Week | | 2021-22 | | 2022-02-28T00:00:00 | East | Award | Kia Motors | KIPWK | |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/drafthistory.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import LeagueID, SeasonYearNullable
4 |
5 |
6 | class DraftHistory(Endpoint):
7 | endpoint = "drafthistory"
8 | expected_data = {
9 | "DraftHistory": [
10 | "PERSON_ID",
11 | "PLAYER_NAME",
12 | "SEASON",
13 | "ROUND_NUMBER",
14 | "ROUND_PICK",
15 | "OVERALL_PICK",
16 | "DRAFT_TYPE",
17 | "TEAM_ID",
18 | "TEAM_CITY",
19 | "TEAM_NAME",
20 | "TEAM_ABBREVIATION",
21 | "ORGANIZATION",
22 | "ORGANIZATION_TYPE",
23 | ]
24 | }
25 |
26 | nba_response = None
27 | data_sets = None
28 | player_stats = None
29 | team_stats = None
30 | headers = None
31 |
32 | def __init__(
33 | self,
34 | league_id=LeagueID.default,
35 | college_nullable="",
36 | overall_pick_nullable="",
37 | round_num_nullable="",
38 | round_pick_nullable="",
39 | season_year_nullable=SeasonYearNullable.default,
40 | team_id_nullable="",
41 | topx_nullable="",
42 | proxy=None,
43 | headers=None,
44 | timeout=30,
45 | get_request=True,
46 | ):
47 | self.proxy = proxy
48 | if headers is not None:
49 | self.headers = headers
50 | self.timeout = timeout
51 | self.parameters = {
52 | "LeagueID": league_id,
53 | "College": college_nullable,
54 | "OverallPick": overall_pick_nullable,
55 | "RoundNum": round_num_nullable,
56 | "RoundPick": round_pick_nullable,
57 | "Season": season_year_nullable,
58 | "TeamID": team_id_nullable,
59 | "TopX": topx_nullable,
60 | }
61 | if get_request:
62 | self.get_request()
63 |
64 | def get_request(self):
65 | self.nba_response = NBAStatsHTTP().send_api_request(
66 | endpoint=self.endpoint,
67 | parameters=self.parameters,
68 | proxy=self.proxy,
69 | headers=self.headers,
70 | timeout=self.timeout,
71 | )
72 | self.load_response()
73 |
74 | def load_response(self):
75 | data_sets = self.nba_response.get_data_sets()
76 | self.data_sets = [
77 | Endpoint.DataSet(data=data_set)
78 | for data_set_name, data_set in data_sets.items()
79 | ]
80 | self.draft_history = Endpoint.DataSet(data=data_sets["DraftHistory"])
81 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/franchiseplayers.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import (
4 | LeagueID,
5 | PerModeDetailed,
6 | SeasonTypeAllStar,
7 | )
8 |
9 |
10 | class FranchisePlayers(Endpoint):
11 | endpoint = "franchiseplayers"
12 | expected_data = {
13 | "FranchisePlayers": [
14 | "LEAGUE_ID",
15 | "TEAM_ID",
16 | "TEAM",
17 | "PERSON_ID",
18 | "PLAYER",
19 | "SEASON_TYPE",
20 | "ACTIVE_WITH_TEAM",
21 | "GP",
22 | "FGM",
23 | "FGA",
24 | "FG_PCT",
25 | "FG3M",
26 | "FG3A",
27 | "FG3_PCT",
28 | "FTM",
29 | "FTA",
30 | "FT_PCT",
31 | "OREB",
32 | "DREB",
33 | "REB",
34 | "AST",
35 | "PF",
36 | "STL",
37 | "TOV",
38 | "BLK",
39 | "PTS",
40 | ]
41 | }
42 |
43 | nba_response = None
44 | data_sets = None
45 | player_stats = None
46 | team_stats = None
47 | headers = None
48 |
49 | def __init__(
50 | self,
51 | team_id,
52 | league_id=LeagueID.default,
53 | per_mode_detailed=PerModeDetailed.default,
54 | season_type_all_star=SeasonTypeAllStar.default,
55 | proxy=None,
56 | headers=None,
57 | timeout=30,
58 | get_request=True,
59 | ):
60 | self.proxy = proxy
61 | if headers is not None:
62 | self.headers = headers
63 | self.timeout = timeout
64 | self.parameters = {
65 | "TeamID": team_id,
66 | "LeagueID": league_id,
67 | "PerMode": per_mode_detailed,
68 | "SeasonType": season_type_all_star,
69 | }
70 | if get_request:
71 | self.get_request()
72 |
73 | def get_request(self):
74 | self.nba_response = NBAStatsHTTP().send_api_request(
75 | endpoint=self.endpoint,
76 | parameters=self.parameters,
77 | proxy=self.proxy,
78 | headers=self.headers,
79 | timeout=self.timeout,
80 | )
81 | self.load_response()
82 |
83 | def load_response(self):
84 | data_sets = self.nba_response.get_data_sets()
85 | self.data_sets = [
86 | Endpoint.DataSet(data=data_set)
87 | for data_set_name, data_set in data_sets.items()
88 | ]
89 | self.franchise_players = Endpoint.DataSet(data=data_sets["FranchisePlayers"])
90 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/playercareerbycollege_output.md:
--------------------------------------------------------------------------------
1 | PlayerCareerByCollege:
2 |
3 | | PLAYER_ID | PLAYER_NAME | COLLEGE | GP | MIN | FGM | FGA | FG_PCT | FG3M | FG3A | FG3_PCT | FTM | FTA | FT_PCT | OREB | DREB | REB | AST | STL | BLK | TOV | PF | PTS |
4 | |------------:|:-----------------|:-----------|-----:|------:|------:|------:|---------:|-------:|-------:|-----------:|------:|------:|---------:|-------:|-------:|------:|------:|------:|------:|------:|-----:|------:|
5 | | 76970 | John Havlicek | Ohio State | 1270 | 46471 | 10513 | 23930 | 0.439323 | nan | nan | nan | 5369 | 6589 | 0.814842 | 610 | 1389 | 8007 | 6114 | 476 | 117 | 204 | 3281 | 26395 |
6 | | 201144 | Mike Conley | Ohio State | 1101 | 34839 | 5597 | 12736 | 0.439462 | 1803 | 4655 | 0.387325 | 2891 | 3512 | 0.823177 | 526 | 2746 | 3272 | 6306 | 1524 | 228 | 2105 | 2159 | 15888 |
7 | | 77418 | Jerry Lucas | Ohio State | 829 | 32131 | 5709 | 11441 | 0.498994 | nan | nan | nan | 2635 | 3365 | 0.78306 | 62 | 312 | 12942 | 2730 | 28 | 24 | nan | 2389 | 14053 |
8 | | 754 | Jim Jackson | Ohio State | 885 | 29068 | 4811 | 11247 | 0.427758 | 881 | 2413 | 0.365105 | 2187 | 2651 | 0.824971 | 1190 | 2962 | 4152 | 2851 | 726 | 188 | 2179 | 1972 | 12690 |
9 | | 2072 | Michael Redd | Ohio State | 629 | 20104 | 4207 | 9405 | 0.447315 | 1045 | 2751 | 0.379861 | 2513 | 2998 | 0.838225 | 622 | 1789 | 2411 | 1338 | 579 | 66 | 963 | 1002 | 11972 |
10 | | 1006 | Herb Williams | Ohio State | 1102 | 28484 | 5037 | 10781 | 0.46721 | 8 | 84 | 0.095238 | 1862 | 2675 | 0.696074 | 1624 | 4885 | 6509 | 1856 | 605 | 1605 | 1929 | 2876 | 11944 |
11 | | 1626156 | D'Angelo Russell | Ohio State | 571 | 17265 | 3659 | 8513 | 0.429813 | 1463 | 3961 | 0.369351 | 1355 | 1710 | 0.792397 | 282 | 1672 | 1954 | 3289 | 610 | 184 | 1538 | 1086 | 10136 |
12 | | 77169 | Neil Johnston | Ohio State | 516 | 18298 | 3303 | 7435 | 0.44425 | nan | nan | nan | 3417 | 4447 | 0.768383 | nan | nan | 5856 | 1269 | nan | nan | nan | 1681 | 10023 |
13 | | 76338 | Tony Campbell | Ohio State | 690 | 15180 | 3180 | 6981 | 0.455522 | 67 | 264 | 0.253787 | 1567 | 1984 | 0.789818 | 912 | 1205 | 2117 | 1019 | 582 | 157 | 1083 | 1536 | 7994 |
14 | | 77967 | Arnie Risen | Ohio State | 637 | 12690 | 2610 | 6850 | 0.381021 | nan | nan | nan | 2413 | 3451 | 0.699217 | nan | nan | 5011 | 1058 | nan | nan | nan | 2449 | 7633 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/cumestatsteamgames.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import (
4 | LeagueID,
5 | Season,
6 | SeasonTypeAllStar,
7 | LocationNullable,
8 | OutcomeNullable,
9 | ConferenceNullable,
10 | DivisionNullable,
11 | )
12 |
13 |
14 | class CumeStatsTeamGames(Endpoint):
15 | endpoint = "cumestatsteamgames"
16 | expected_data = {"CumeStatsTeamGames": ["MATCHUP", "GAME_ID"]}
17 |
18 | nba_response = None
19 | data_sets = None
20 | player_stats = None
21 | team_stats = None
22 | headers = None
23 |
24 | def __init__(
25 | self,
26 | team_id,
27 | league_id=LeagueID.default,
28 | season=Season.default,
29 | season_type_all_star=SeasonTypeAllStar.default,
30 | location_nullable=LocationNullable.default,
31 | outcome_nullable=OutcomeNullable.default,
32 | season_id_nullable="",
33 | vs_conference_nullable=ConferenceNullable.default,
34 | vs_division_nullable=DivisionNullable.default,
35 | vs_team_id_nullable="",
36 | proxy=None,
37 | headers=None,
38 | timeout=30,
39 | get_request=True,
40 | ):
41 | self.proxy = proxy
42 | if headers is not None:
43 | self.headers = headers
44 | self.timeout = timeout
45 | self.parameters = {
46 | "TeamID": team_id,
47 | "LeagueID": league_id,
48 | "Season": season,
49 | "SeasonType": season_type_all_star,
50 | "Location": location_nullable,
51 | "Outcome": outcome_nullable,
52 | "SeasonID": season_id_nullable,
53 | "VsConference": vs_conference_nullable,
54 | "VsDivision": vs_division_nullable,
55 | "VsTeamID": vs_team_id_nullable,
56 | }
57 | if get_request:
58 | self.get_request()
59 |
60 | def get_request(self):
61 | self.nba_response = NBAStatsHTTP().send_api_request(
62 | endpoint=self.endpoint,
63 | parameters=self.parameters,
64 | proxy=self.proxy,
65 | headers=self.headers,
66 | timeout=self.timeout,
67 | )
68 | self.load_response()
69 |
70 | def load_response(self):
71 | data_sets = self.nba_response.get_data_sets()
72 | self.data_sets = [
73 | Endpoint.DataSet(data=data_set)
74 | for data_set_name, data_set in data_sets.items()
75 | ]
76 | self.cume_stats_team_games = Endpoint.DataSet(
77 | data=data_sets["CumeStatsTeamGames"]
78 | )
79 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/leaguedashptdefend_output.md:
--------------------------------------------------------------------------------
1 | LeagueDashPTDefend:
2 |
3 | | CLOSE_DEF_PERSON_ID | PLAYER_NAME | PLAYER_LAST_TEAM_ID | PLAYER_LAST_TEAM_ABBREVIATION | PLAYER_POSITION | AGE | GP | G | FREQ | D_FGM | D_FGA | D_FG_PCT | NORMAL_FG_PCT | PCT_PLUSMINUS |
4 | |----------------------:|:-----------------|----------------------:|:--------------------------------|:------------------|------:|-----:|----:|-------:|--------:|--------:|-----------:|----------------:|----------------:|
5 | | 201572 | Brook Lopez | 1610612749 | MIL | C | 36 | 79 | 79 | 1 | 835 | 1751 | 0.477 | 0.498 | -0.022 |
6 | | 203999 | Nikola Jokic | 1610612743 | DEN | C | 29 | 78 | 78 | 1 | 796 | 1559 | 0.511 | 0.505 | 0.005 |
7 | | 203497 | Rudy Gobert | 1610612750 | MIN | C | 31 | 76 | 76 | 1 | 626 | 1440 | 0.435 | 0.495 | -0.06 |
8 | | 203076 | Anthony Davis | 1610612747 | LAL | F-C | 31 | 76 | 76 | 1 | 679 | 1438 | 0.472 | 0.495 | -0.023 |
9 | | 1627734 | Domantas Sabonis | 1610612758 | SAC | F-C | 28 | 82 | 82 | 1 | 683 | 1407 | 0.485 | 0.505 | -0.019 |
10 | | 1631096 | Chet Holmgren | 1610612760 | OKC | C-F | 22 | 82 | 82 | 1 | 605 | 1329 | 0.455 | 0.499 | -0.044 |
11 | | 1628386 | Jarrett Allen | 1610612739 | CLE | C | 26 | 76 | 76 | 1 | 624 | 1278 | 0.488 | 0.5 | -0.012 |
12 | | 1630166 | Deni Avdija | 1610612764 | WAS | F | 23 | 75 | 75 | 1 | 596 | 1255 | 0.475 | 0.479 | -0.004 |
13 | | 202696 | Nikola Vucevic | 1610612741 | CHI | C | 33 | 75 | 75 | 1 | 606 | 1227 | 0.494 | 0.5 | -0.007 |
14 | | 1629632 | Coby White | 1610612741 | CHI | G | 24 | 78 | 78 | 1 | 605 | 1196 | 0.506 | 0.468 | 0.038 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/draftboard.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import LeagueID, SeasonYear
4 |
5 |
6 | class DraftBoard(Endpoint):
7 | endpoint = "draftboard"
8 | expected_data = {
9 | "DraftBoard": [
10 | "PERSON_ID",
11 | "PLAYER_NAME",
12 | "SEASON",
13 | "ROUND_NUMBER",
14 | "ROUND_PICK",
15 | "OVERALL_PICK",
16 | "TEAM_ID",
17 | "TEAM_CITY",
18 | "TEAM_NAME",
19 | "TEAM_ABBREVIATION",
20 | "ORGANIZATION",
21 | "ORGANIZATION_TYPE",
22 | "HEIGHT",
23 | "WEIGHT",
24 | "POSITION",
25 | "JERSEY_NUMBER",
26 | "BIRTHDATE",
27 | "AGE",
28 | ]
29 | }
30 |
31 | nba_response = None
32 | data_sets = None
33 | player_stats = None
34 | team_stats = None
35 | headers = None
36 |
37 | def __init__(
38 | self,
39 | league_id=LeagueID.default,
40 | season_year=SeasonYear.default,
41 | college_nullable="",
42 | overall_pick_nullable="",
43 | round_num_nullable="",
44 | round_pick_nullable="",
45 | team_id_nullable="",
46 | topx_nullable="",
47 | proxy=None,
48 | headers=None,
49 | timeout=30,
50 | get_request=True,
51 | ):
52 | self.proxy = proxy
53 | if headers is not None:
54 | self.headers = headers
55 | self.timeout = timeout
56 | self.parameters = {
57 | "LeagueID": league_id,
58 | "Season": season_year,
59 | "College": college_nullable,
60 | "OverallPick": overall_pick_nullable,
61 | "RoundNum": round_num_nullable,
62 | "RoundPick": round_pick_nullable,
63 | "TeamID": team_id_nullable,
64 | "TopX": topx_nullable,
65 | }
66 | if get_request:
67 | self.get_request()
68 |
69 | def get_request(self):
70 | self.nba_response = NBAStatsHTTP().send_api_request(
71 | endpoint=self.endpoint,
72 | parameters=self.parameters,
73 | proxy=self.proxy,
74 | headers=self.headers,
75 | timeout=self.timeout,
76 | )
77 | self.load_response()
78 |
79 | def load_response(self):
80 | data_sets = self.nba_response.get_data_sets()
81 | self.data_sets = [
82 | Endpoint.DataSet(data=data_set)
83 | for data_set_name, data_set in data_sets.items()
84 | ]
85 | self.draft_board = Endpoint.DataSet(data=data_sets["DraftBoard"])
86 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/playercareerbycollege.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import (
4 | LeagueID,
5 | PerModeSimple,
6 | SeasonTypeAllStar,
7 | SeasonNullable,
8 | )
9 |
10 |
11 | class PlayerCareerByCollege(Endpoint):
12 | endpoint = "playercareerbycollege"
13 | expected_data = {
14 | "PlayerCareerByCollege": [
15 | "PLAYER_ID",
16 | "PLAYER_NAME",
17 | "COLLEGE",
18 | "GP",
19 | "MIN",
20 | "FGM",
21 | "FGA",
22 | "FG_PCT",
23 | "FG3M",
24 | "FG3A",
25 | "FG3_PCT",
26 | "FTM",
27 | "FTA",
28 | "FT_PCT",
29 | "OREB",
30 | "DREB",
31 | "REB",
32 | "AST",
33 | "STL",
34 | "BLK",
35 | "TOV",
36 | "PF",
37 | "PTS",
38 | ]
39 | }
40 |
41 | nba_response = None
42 | data_sets = None
43 | player_stats = None
44 | team_stats = None
45 | headers = None
46 |
47 | def __init__(
48 | self,
49 | college,
50 | league_id=LeagueID.default,
51 | per_mode_simple=PerModeSimple.default,
52 | season_type_all_star=SeasonTypeAllStar.default,
53 | season_nullable=SeasonNullable.default,
54 | proxy=None,
55 | headers=None,
56 | timeout=30,
57 | get_request=True,
58 | ):
59 | self.proxy = proxy
60 | if headers is not None:
61 | self.headers = headers
62 | self.timeout = timeout
63 | self.parameters = {
64 | "College": college,
65 | "LeagueID": league_id,
66 | "PerMode": per_mode_simple,
67 | "SeasonType": season_type_all_star,
68 | "Season": season_nullable,
69 | }
70 | if get_request:
71 | self.get_request()
72 |
73 | def get_request(self):
74 | self.nba_response = NBAStatsHTTP().send_api_request(
75 | endpoint=self.endpoint,
76 | parameters=self.parameters,
77 | proxy=self.proxy,
78 | headers=self.headers,
79 | timeout=self.timeout,
80 | )
81 | self.load_response()
82 |
83 | def load_response(self):
84 | data_sets = self.nba_response.get_data_sets()
85 | self.data_sets = [
86 | Endpoint.DataSet(data=data_set)
87 | for data_set_name, data_set in data_sets.items()
88 | ]
89 | self.player_career_by_college = Endpoint.DataSet(
90 | data=data_sets["PlayerCareerByCollege"]
91 | )
92 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/boxscoredefensivev2.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 |
4 |
5 | class BoxScoreDefensiveV2(Endpoint):
6 | endpoint = "boxscoredefensivev2"
7 | expected_data = {
8 | "PlayerStats": [
9 | "gameId",
10 | "teamId",
11 | "teamCity",
12 | "teamName",
13 | "teamTricode",
14 | "teamSlug",
15 | "personId",
16 | "firstName",
17 | "familyName",
18 | "nameI",
19 | "playerSlug",
20 | "position",
21 | "comment",
22 | "jerseyNum",
23 | "matchupMinutes",
24 | "partialPossessions",
25 | "switchesOn",
26 | "playerPoints",
27 | "defensiveRebounds",
28 | "matchupAssists",
29 | "matchupTurnovers",
30 | "steals",
31 | "blocks",
32 | "matchupFieldGoalsMade",
33 | "matchupFieldGoalsAttempted",
34 | "matchupFieldGoalPercentage",
35 | "matchupThreePointersMade",
36 | "matchupThreePointersAttempted",
37 | "matchupThreePointerPercentage",
38 | ],
39 | "TeamStats": [
40 | "gameId",
41 | "teamId",
42 | "teamCity",
43 | "teamName",
44 | "teamTricode",
45 | "teamSlug",
46 | "minutes",
47 | ],
48 | }
49 |
50 | nba_response = None
51 | data_sets = None
52 | player_stats = None
53 | team_stats = None
54 | headers = None
55 |
56 | def __init__(self, game_id, proxy=None, headers=None, timeout=30, get_request=True):
57 | self.proxy = proxy
58 | if headers is not None:
59 | self.headers = headers
60 | self.timeout = timeout
61 | self.parameters = {"GameID": game_id}
62 | if get_request:
63 | self.get_request()
64 |
65 | def get_request(self):
66 | self.nba_response = NBAStatsHTTP().send_api_request(
67 | endpoint=self.endpoint,
68 | parameters=self.parameters,
69 | proxy=self.proxy,
70 | headers=self.headers,
71 | timeout=self.timeout,
72 | )
73 | self.load_response()
74 |
75 | def load_response(self):
76 | data_sets = self.nba_response.get_data_sets(self.endpoint)
77 | self.data_sets = [
78 | Endpoint.DataSet(data=data_set)
79 | for data_set_name, data_set in data_sets.items()
80 | ]
81 | self.player_stats = Endpoint.DataSet(data=data_sets["PlayerStats"])
82 | self.team_stats = Endpoint.DataSet(data=data_sets["TeamStats"])
83 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/commonteamroster.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import Season, LeagueIDNullable
4 |
5 |
6 | class CommonTeamRoster(Endpoint):
7 | endpoint = "commonteamroster"
8 | expected_data = {
9 | "Coaches": [
10 | "TEAM_ID",
11 | "SEASON",
12 | "COACH_ID",
13 | "FIRST_NAME",
14 | "LAST_NAME",
15 | "COACH_NAME",
16 | "IS_ASSISTANT",
17 | "COACH_TYPE",
18 | "SORT_SEQUENCE",
19 | ],
20 | "CommonTeamRoster": [
21 | "TeamID",
22 | "SEASON",
23 | "LeagueID",
24 | "PLAYER",
25 | "PLAYER_SLUG",
26 | "NUM",
27 | "POSITION",
28 | "HEIGHT",
29 | "WEIGHT",
30 | "BIRTH_DATE",
31 | "AGE",
32 | "EXP",
33 | "SCHOOL",
34 | "PLAYER_ID",
35 | ],
36 | }
37 |
38 | nba_response = None
39 | data_sets = None
40 | player_stats = None
41 | team_stats = None
42 | headers = None
43 |
44 | def __init__(
45 | self,
46 | team_id,
47 | season=Season.default,
48 | league_id_nullable=LeagueIDNullable.default,
49 | proxy=None,
50 | headers=None,
51 | timeout=30,
52 | get_request=True,
53 | ):
54 | self.proxy = proxy
55 | if headers is not None:
56 | self.headers = headers
57 | self.timeout = timeout
58 | self.parameters = {
59 | "TeamID": team_id,
60 | "Season": season,
61 | "LeagueID": league_id_nullable,
62 | }
63 | if get_request:
64 | self.get_request()
65 |
66 | def get_request(self):
67 | self.nba_response = NBAStatsHTTP().send_api_request(
68 | endpoint=self.endpoint,
69 | parameters=self.parameters,
70 | proxy=self.proxy,
71 | headers=self.headers,
72 | timeout=self.timeout,
73 | )
74 | self.load_response()
75 |
76 | def load_response(self):
77 | data_sets = self.nba_response.get_data_sets()
78 | self.data_sets = [
79 | Endpoint.DataSet(data=data_set)
80 | for data_set_name, data_set in data_sets.items()
81 | ]
82 | # Handle cases where Coaches dataset may not be present (#553)
83 | self.coaches = Endpoint.DataSet(
84 | data=data_sets.get("Coaches", {"headers": self.expected_data["Coaches"], "data": []})
85 | )
86 | self.common_team_roster = Endpoint.DataSet(data=data_sets["CommonTeamRoster"])
87 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/leaguedashoppptshot_output.md:
--------------------------------------------------------------------------------
1 | LeagueDashPTShots:
2 |
3 | | TEAM_ID | TEAM_NAME | TEAM_ABBREVIATION | GP | G | FGA_FREQUENCY | FGM | FGA | FG_PCT | EFG_PCT | FG2A_FREQUENCY | FG2M | FG2A | FG2_PCT | FG3A_FREQUENCY | FG3M | FG3A | FG3_PCT |
4 | |-----------:|:----------------------|:--------------------|-----:|----:|----------------:|------:|------:|---------:|----------:|-----------------:|-------:|-------:|----------:|-----------------:|-------:|-------:|----------:|
5 | | 1610612764 | Washington Wizards | WAS | 82 | 82 | 1 | 3772 | 7608 | 0.496 | 0.562 | 0.635 | 2766 | 4829 | 0.573 | 0.365 | 1006 | 2779 | 0.362 |
6 | | 1610612749 | Milwaukee Bucks | MIL | 82 | 82 | 1 | 3542 | 7533 | 0.47 | 0.539 | 0.616 | 2510 | 4638 | 0.541 | 0.384 | 1032 | 2895 | 0.356 |
7 | | 1610612747 | Los Angeles Lakers | LAL | 81 | 81 | 1 | 3558 | 7480 | 0.476 | 0.552 | 0.596 | 2415 | 4455 | 0.542 | 0.404 | 1143 | 3025 | 0.378 |
8 | | 1610612759 | San Antonio Spurs | SAS | 81 | 81 | 1 | 3642 | 7477 | 0.487 | 0.556 | 0.631 | 2612 | 4721 | 0.553 | 0.369 | 1030 | 2756 | 0.374 |
9 | | 1610612738 | Boston Celtics | BOS | 81 | 81 | 1 | 3358 | 7422 | 0.452 | 0.523 | 0.599 | 2309 | 4446 | 0.519 | 0.401 | 1049 | 2976 | 0.352 |
10 | | 1610612762 | Utah Jazz | UTA | 81 | 81 | 1 | 3596 | 7417 | 0.485 | 0.565 | 0.591 | 2403 | 4383 | 0.548 | 0.409 | 1193 | 3034 | 0.393 |
11 | | 1610612761 | Toronto Raptors | TOR | 81 | 81 | 1 | 3618 | 7372 | 0.491 | 0.566 | 0.601 | 2515 | 4434 | 0.567 | 0.399 | 1103 | 2938 | 0.375 |
12 | | 1610612737 | Atlanta Hawks | ATL | 82 | 82 | 1 | 3630 | 7354 | 0.494 | 0.571 | 0.596 | 2489 | 4380 | 0.568 | 0.404 | 1141 | 2974 | 0.384 |
13 | | 1610612754 | Indiana Pacers | IND | 82 | 82 | 1 | 3644 | 7335 | 0.497 | 0.556 | 0.674 | 2771 | 4941 | 0.561 | 0.326 | 873 | 2394 | 0.365 |
14 | | 1610612760 | Oklahoma City Thunder | OKC | 82 | 82 | 1 | 3327 | 7320 | 0.455 | 0.53 | 0.583 | 2226 | 4270 | 0.521 | 0.417 | 1101 | 3050 | 0.361 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints_output/leaguedashteamptshot_output.md:
--------------------------------------------------------------------------------
1 | LeagueDashPTShots:
2 |
3 | | TEAM_ID | TEAM_NAME | TEAM_ABBREVIATION | GP | G | FGA_FREQUENCY | FGM | FGA | FG_PCT | EFG_PCT | FG2A_FREQUENCY | FG2M | FG2A | FG2_PCT | FG3A_FREQUENCY | FG3M | FG3A | FG3_PCT |
4 | |-----------:|:----------------------|:--------------------|-----:|----:|----------------:|------:|------:|---------:|----------:|-----------------:|-------:|-------:|----------:|-----------------:|-------:|-------:|----------:|
5 | | 1610612754 | Indiana Pacers | IND | 82 | 82 | 1 | 3841 | 7580 | 0.507 | 0.578 | 0.619 | 2762 | 4695 | 0.588 | 0.381 | 1079 | 2885 | 0.374 |
6 | | 1610612737 | Atlanta Hawks | ATL | 82 | 82 | 1 | 3514 | 7538 | 0.466 | 0.54 | 0.593 | 2395 | 4467 | 0.536 | 0.407 | 1119 | 3071 | 0.364 |
7 | | 1610612764 | Washington Wizards | WAS | 82 | 82 | 1 | 3509 | 7464 | 0.47 | 0.538 | 0.611 | 2499 | 4557 | 0.548 | 0.389 | 1010 | 2907 | 0.347 |
8 | | 1610612745 | Houston Rockets | HOU | 82 | 82 | 1 | 3415 | 7431 | 0.46 | 0.53 | 0.602 | 2374 | 4477 | 0.53 | 0.398 | 1041 | 2954 | 0.352 |
9 | | 1610612758 | Sacramento Kings | SAC | 82 | 82 | 1 | 3536 | 7421 | 0.476 | 0.556 | 0.568 | 2363 | 4216 | 0.56 | 0.432 | 1173 | 3205 | 0.366 |
10 | | 1610612759 | San Antonio Spurs | SAS | 81 | 81 | 1 | 3390 | 7343 | 0.462 | 0.531 | 0.599 | 2371 | 4395 | 0.539 | 0.401 | 1019 | 2948 | 0.346 |
11 | | 1610612760 | Oklahoma City Thunder | OKC | 82 | 82 | 1 | 3653 | 7324 | 0.499 | 0.573 | 0.617 | 2563 | 4519 | 0.567 | 0.383 | 1090 | 2805 | 0.389 |
12 | | 1610612744 | Golden State Warriors | GSW | 81 | 81 | 1 | 3489 | 7312 | 0.477 | 0.558 | 0.575 | 2308 | 4207 | 0.549 | 0.425 | 1181 | 3105 | 0.38 |
13 | | 1610612738 | Boston Celtics | BOS | 81 | 81 | 1 | 3555 | 7302 | 0.487 | 0.578 | 0.528 | 2219 | 3859 | 0.575 | 0.472 | 1336 | 3443 | 0.388 |
14 | | 1610612762 | Utah Jazz | UTA | 81 | 81 | 1 | 3396 | 7276 | 0.467 | 0.539 | 0.592 | 2344 | 4309 | 0.544 | 0.408 | 1052 | 2967 | 0.355 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/playergamelog.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import Season, SeasonTypeAllStar, LeagueIDNullable
4 |
5 |
6 | class PlayerGameLog(Endpoint):
7 | endpoint = "playergamelog"
8 | expected_data = {
9 | "PlayerGameLog": [
10 | "SEASON_ID",
11 | "Player_ID",
12 | "Game_ID",
13 | "GAME_DATE",
14 | "MATCHUP",
15 | "WL",
16 | "MIN",
17 | "FGM",
18 | "FGA",
19 | "FG_PCT",
20 | "FG3M",
21 | "FG3A",
22 | "FG3_PCT",
23 | "FTM",
24 | "FTA",
25 | "FT_PCT",
26 | "OREB",
27 | "DREB",
28 | "REB",
29 | "AST",
30 | "STL",
31 | "BLK",
32 | "TOV",
33 | "PF",
34 | "PTS",
35 | "PLUS_MINUS",
36 | "VIDEO_AVAILABLE",
37 | ]
38 | }
39 |
40 | nba_response = None
41 | data_sets = None
42 | player_stats = None
43 | team_stats = None
44 | headers = None
45 |
46 | def __init__(
47 | self,
48 | player_id,
49 | season=Season.default,
50 | season_type_all_star=SeasonTypeAllStar.default,
51 | date_from_nullable="",
52 | date_to_nullable="",
53 | league_id_nullable=LeagueIDNullable.default,
54 | proxy=None,
55 | headers=None,
56 | timeout=30,
57 | get_request=True,
58 | ):
59 | self.proxy = proxy
60 | if headers is not None:
61 | self.headers = headers
62 | self.timeout = timeout
63 | self.parameters = {
64 | "PlayerID": player_id,
65 | "Season": season,
66 | "SeasonType": season_type_all_star,
67 | "DateFrom": date_from_nullable,
68 | "DateTo": date_to_nullable,
69 | "LeagueID": league_id_nullable,
70 | }
71 | if get_request:
72 | self.get_request()
73 |
74 | def get_request(self):
75 | self.nba_response = NBAStatsHTTP().send_api_request(
76 | endpoint=self.endpoint,
77 | parameters=self.parameters,
78 | proxy=self.proxy,
79 | headers=self.headers,
80 | timeout=self.timeout,
81 | )
82 | self.load_response()
83 |
84 | def load_response(self):
85 | data_sets = self.nba_response.get_data_sets()
86 | self.data_sets = [
87 | Endpoint.DataSet(data=data_set)
88 | for data_set_name, data_set in data_sets.items()
89 | ]
90 | self.player_game_log = Endpoint.DataSet(data=data_sets["PlayerGameLog"])
91 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/teamestimatedmetrics.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import LeagueID, Season, SeasonType
4 |
5 |
6 | class TeamEstimatedMetrics(Endpoint):
7 | endpoint = "teamestimatedmetrics"
8 | expected_data = {
9 | "TeamEstimatedMetrics": [
10 | "TEAM_NAME",
11 | "TEAM_ID",
12 | "GP",
13 | "W",
14 | "L",
15 | "W_PCT",
16 | "MIN",
17 | "E_OFF_RATING",
18 | "E_DEF_RATING",
19 | "E_NET_RATING",
20 | "E_PACE",
21 | "E_AST_RATIO",
22 | "E_OREB_PCT",
23 | "E_DREB_PCT",
24 | "E_REB_PCT",
25 | "E_TM_TOV_PCT",
26 | "GP_RANK",
27 | "W_RANK",
28 | "L_RANK",
29 | "W_PCT_RANK",
30 | "MIN_RANK",
31 | "E_OFF_RATING_RANK",
32 | "E_DEF_RATING_RANK",
33 | "E_NET_RATING_RANK",
34 | "E_AST_RATIO_RANK",
35 | "E_OREB_PCT_RANK",
36 | "E_DREB_PCT_RANK",
37 | "E_REB_PCT_RANK",
38 | "E_TM_TOV_PCT_RANK",
39 | "E_PACE_RANK",
40 | ]
41 | }
42 |
43 | nba_response = None
44 | data_sets = None
45 | player_stats = None
46 | team_stats = None
47 | headers = None
48 |
49 | def __init__(
50 | self,
51 | league_id=LeagueID.default,
52 | season=Season.default,
53 | season_type=SeasonType.default,
54 | proxy=None,
55 | headers=None,
56 | timeout=30,
57 | get_request=True,
58 | ):
59 | self.proxy = proxy
60 | if headers is not None:
61 | self.headers = headers
62 | self.timeout = timeout
63 | self.parameters = {
64 | "LeagueID": league_id,
65 | "Season": season,
66 | "SeasonType": season_type,
67 | }
68 | if get_request:
69 | self.get_request()
70 |
71 | def get_request(self):
72 | self.nba_response = NBAStatsHTTP().send_api_request(
73 | endpoint=self.endpoint,
74 | parameters=self.parameters,
75 | proxy=self.proxy,
76 | headers=self.headers,
77 | timeout=self.timeout,
78 | )
79 | self.load_response()
80 |
81 | def load_response(self):
82 | data_sets = self.nba_response.get_data_sets()
83 | self.data_sets = [
84 | Endpoint.DataSet(data=data_set)
85 | for data_set_name, data_set in data_sets.items()
86 | ]
87 | self.team_estimated_metrics = Endpoint.DataSet(
88 | data=data_sets["TeamEstimatedMetrics"]
89 | )
90 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/teamyearbyyearstats.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import LeagueID, PerModeSimple, SeasonTypeAllStar
4 |
5 |
6 | class TeamYearByYearStats(Endpoint):
7 | endpoint = "teamyearbyyearstats"
8 | expected_data = {
9 | "TeamStats": [
10 | "TEAM_ID",
11 | "TEAM_CITY",
12 | "TEAM_NAME",
13 | "YEAR",
14 | "GP",
15 | "WINS",
16 | "LOSSES",
17 | "WIN_PCT",
18 | "CONF_RANK",
19 | "DIV_RANK",
20 | "PO_WINS",
21 | "PO_LOSSES",
22 | "CONF_COUNT",
23 | "DIV_COUNT",
24 | "NBA_FINALS_APPEARANCE",
25 | "FGM",
26 | "FGA",
27 | "FG_PCT",
28 | "FG3M",
29 | "FG3A",
30 | "FG3_PCT",
31 | "FTM",
32 | "FTA",
33 | "FT_PCT",
34 | "OREB",
35 | "DREB",
36 | "REB",
37 | "AST",
38 | "PF",
39 | "STL",
40 | "TOV",
41 | "BLK",
42 | "PTS",
43 | "PTS_RANK",
44 | ]
45 | }
46 |
47 | nba_response = None
48 | data_sets = None
49 | player_stats = None
50 | team_stats = None
51 | headers = None
52 |
53 | def __init__(
54 | self,
55 | team_id,
56 | league_id=LeagueID.default,
57 | per_mode_simple=PerModeSimple.default,
58 | season_type_all_star=SeasonTypeAllStar.default,
59 | proxy=None,
60 | headers=None,
61 | timeout=30,
62 | get_request=True,
63 | ):
64 | self.proxy = proxy
65 | if headers is not None:
66 | self.headers = headers
67 | self.timeout = timeout
68 | self.parameters = {
69 | "TeamID": team_id,
70 | "LeagueID": league_id,
71 | "PerMode": per_mode_simple,
72 | "SeasonType": season_type_all_star,
73 | }
74 | if get_request:
75 | self.get_request()
76 |
77 | def get_request(self):
78 | self.nba_response = NBAStatsHTTP().send_api_request(
79 | endpoint=self.endpoint,
80 | parameters=self.parameters,
81 | proxy=self.proxy,
82 | headers=self.headers,
83 | timeout=self.timeout,
84 | )
85 | self.load_response()
86 |
87 | def load_response(self):
88 | data_sets = self.nba_response.get_data_sets()
89 | self.data_sets = [
90 | Endpoint.DataSet(data=data_set)
91 | for data_set_name, data_set in data_sets.items()
92 | ]
93 | self.team_stats = Endpoint.DataSet(data=data_sets["TeamStats"])
94 |
--------------------------------------------------------------------------------
/src/nba_api/stats/endpoints/teamgamelog.py:
--------------------------------------------------------------------------------
1 | from nba_api.stats.endpoints._base import Endpoint
2 | from nba_api.stats.library.http import NBAStatsHTTP
3 | from nba_api.stats.library.parameters import Season, SeasonTypeAllStar, LeagueIDNullable
4 |
5 |
6 | class TeamGameLog(Endpoint):
7 | endpoint = "teamgamelog"
8 | expected_data = {
9 | "TeamGameLog": [
10 | "Team_ID",
11 | "Game_ID",
12 | "GAME_DATE",
13 | "MATCHUP",
14 | "WL",
15 | "W",
16 | "L",
17 | "W_PCT",
18 | "MIN",
19 | "FGM",
20 | "FGA",
21 | "FG_PCT",
22 | "FG3M",
23 | "FG3A",
24 | "FG3_PCT",
25 | "FTM",
26 | "FTA",
27 | "FT_PCT",
28 | "OREB",
29 | "DREB",
30 | "REB",
31 | "AST",
32 | "STL",
33 | "BLK",
34 | "TOV",
35 | "PF",
36 | "PTS",
37 | ]
38 | }
39 |
40 | nba_response = None
41 | data_sets = None
42 | player_stats = None
43 | team_stats = None
44 | headers = None
45 |
46 | def __init__(
47 | self,
48 | team_id,
49 | season=Season.default,
50 | season_type_all_star=SeasonTypeAllStar.default,
51 | date_from_nullable="",
52 | date_to_nullable="",
53 | league_id_nullable=LeagueIDNullable.default,
54 | proxy=None,
55 | headers=None,
56 | timeout=30,
57 | get_request=True,
58 | ):
59 | self.proxy = proxy
60 | if headers is not None:
61 | self.headers = headers
62 | self.timeout = timeout
63 | self.parameters = {
64 | "TeamID": team_id,
65 | "Season": season,
66 | "SeasonType": season_type_all_star,
67 | "DateFrom": date_from_nullable,
68 | "DateTo": date_to_nullable,
69 | "LeagueID": league_id_nullable,
70 | }
71 |
72 | # Initialize dataset attributes
73 | self.team_game_log = None
74 |
75 | if get_request:
76 | self.get_request()
77 |
78 | def get_request(self):
79 | self.nba_response = NBAStatsHTTP().send_api_request(
80 | endpoint=self.endpoint,
81 | parameters=self.parameters,
82 | proxy=self.proxy,
83 | headers=self.headers,
84 | timeout=self.timeout,
85 | )
86 | self.load_response()
87 |
88 | def load_response(self):
89 | data_sets = self.nba_response.get_data_sets()
90 | self.data_sets = [
91 | Endpoint.DataSet(data=data_set)
92 | for data_set_name, data_set in data_sets.items()
93 | ]
94 | self.team_game_log = Endpoint.DataSet(data=data_sets["TeamGameLog"])
95 |
--------------------------------------------------------------------------------
/docs/nba_api/stats/endpoints/draftcombineplayeranthro.md:
--------------------------------------------------------------------------------
1 | # DraftCombinePlayerAnthro
2 | ##### [nba_api/stats/endpoints/draftcombineplayeranthro.py](https://github.com/swar/nba_api/blob/master/src/nba_api/stats/endpoints/draftcombineplayeranthro.py)
3 |
4 | ##### Endpoint URL
5 | >[https://stats.nba.com/stats/draftcombineplayeranthro](https://stats.nba.com/stats/draftcombineplayeranthro)
6 |
7 | ##### Valid URL
8 | >[https://stats.nba.com/stats/draftcombineplayeranthro?LeagueID=00&SeasonYear=2019](https://stats.nba.com/stats/draftcombineplayeranthro?LeagueID=00&SeasonYear=2019)
9 |
10 | ## Parameters
11 | | API Parameter Name | Python Parameter Variable | Pattern | Required | Nullable |
12 | |---------------------------------------------------------------------------------------------------------------------|---------------------------|:-------:|:--------:|:--------:|
13 | | [_**LeagueID**_](https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md#LeagueID) | league_id | | `Y` | |
14 | | [_**SeasonYear**_](https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md#SeasonYear) | season_year | | `Y` | |
15 |
16 | ## Data Sets
17 | #### Results `results`
18 | ```text
19 | ['TEMP_PLAYER_ID', 'PLAYER_ID', 'FIRST_NAME', 'LAST_NAME', 'PLAYER_NAME', 'POSITION', 'HEIGHT_WO_SHOES', 'HEIGHT_WO_SHOES_FT_IN', 'HEIGHT_W_SHOES', 'HEIGHT_W_SHOES_FT_IN', 'WEIGHT', 'WINGSPAN', 'WINGSPAN_FT_IN', 'STANDING_REACH', 'STANDING_REACH_FT_IN', 'BODY_FAT_PCT', 'HAND_LENGTH', 'HAND_WIDTH']
20 | ```
21 |
22 |
23 | ## JSON
24 | ```json
25 | {
26 | "data_sets": {
27 | "Results": [
28 | "TEMP_PLAYER_ID",
29 | "PLAYER_ID",
30 | "FIRST_NAME",
31 | "LAST_NAME",
32 | "PLAYER_NAME",
33 | "POSITION",
34 | "HEIGHT_WO_SHOES",
35 | "HEIGHT_WO_SHOES_FT_IN",
36 | "HEIGHT_W_SHOES",
37 | "HEIGHT_W_SHOES_FT_IN",
38 | "WEIGHT",
39 | "WINGSPAN",
40 | "WINGSPAN_FT_IN",
41 | "STANDING_REACH",
42 | "STANDING_REACH_FT_IN",
43 | "BODY_FAT_PCT",
44 | "HAND_LENGTH",
45 | "HAND_WIDTH"
46 | ]
47 | },
48 | "endpoint": "DraftCombinePlayerAnthro",
49 | "last_validated_date": "2020-08-15",
50 | "nullable_parameters": [],
51 | "parameter_patterns": {
52 | "LeagueID": null,
53 | "SeasonYear": null
54 | },
55 | "parameters": [
56 | "LeagueID",
57 | "SeasonYear"
58 | ],
59 | "required_parameters": [
60 | "LeagueID",
61 | "SeasonYear"
62 | ],
63 | "status": "success"
64 | }
65 | ```
66 |
67 | Last validated 2020-08-16
--------------------------------------------------------------------------------