nbastatpy 0.1.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of nbastatpy might be problematic. Click here for more details.
- nbastatpy-0.1.6/LICENSE +21 -0
- nbastatpy-0.1.6/PKG-INFO +67 -0
- nbastatpy-0.1.6/README.md +41 -0
- nbastatpy-0.1.6/pyproject.toml +36 -0
- nbastatpy-0.1.6/src/nbastatpy/__init__.py +1 -0
- nbastatpy-0.1.6/src/nbastatpy/game.py +153 -0
- nbastatpy-0.1.6/src/nbastatpy/player.py +507 -0
- nbastatpy-0.1.6/src/nbastatpy/season.py +578 -0
- nbastatpy-0.1.6/src/nbastatpy/team.py +436 -0
- nbastatpy-0.1.6/src/nbastatpy/utils.py +98 -0
nbastatpy-0.1.6/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 aberghammer-analytics
|
|
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.
|
nbastatpy-0.1.6/PKG-INFO
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: nbastatpy
|
|
3
|
+
Version: 0.1.6
|
|
4
|
+
Summary: An easy-to-use wrapper for nba_api to easily find data for a player, game, team, or season
|
|
5
|
+
Home-page: https://github.com/aberghammer-analytics/NBAStatPy
|
|
6
|
+
Keywords: basketball,data,nba,sports,stats
|
|
7
|
+
Maintainer: Anthony Berghammer
|
|
8
|
+
Maintainer-email: aberghammer.analytics@gmail.com
|
|
9
|
+
Requires-Python: >=3.10,<4.0
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Requires-Dist: bs4 (>=0.0.2,<0.0.3)
|
|
16
|
+
Requires-Dist: loguru (>=0.7.2,<0.8.0)
|
|
17
|
+
Requires-Dist: nba_api (>=1.4.1,<2.0.0)
|
|
18
|
+
Requires-Dist: pandas (>=2.2.2,<3.0.0)
|
|
19
|
+
Requires-Dist: pillow (>=10.3.0,<11.0.0)
|
|
20
|
+
Requires-Dist: requests (>=2.31.0,<3.0.0)
|
|
21
|
+
Requires-Dist: rich (>=13.7.1,<14.0.0)
|
|
22
|
+
Project-URL: Documentation, https://github.com/aberghammer-analytics/NBAStatPy/blob/main/README.md
|
|
23
|
+
Project-URL: Repository, https://github.com/aberghammer-analytics/NBAStatPy
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# NBAStatPy
|
|
27
|
+
|
|
28
|
+
## Overview
|
|
29
|
+
|
|
30
|
+
This is an easy-to-use wrapper for the `nba_api` package. The goal is to be able to easily access and find data for a player, game, team, or season.
|
|
31
|
+
|
|
32
|
+
The data is accessed through a class based on how you're searching for it. A quickstart example is shown below. Currently there are 4 classes:
|
|
33
|
+
|
|
34
|
+
- `Game`
|
|
35
|
+
- `Player`
|
|
36
|
+
- `Season`
|
|
37
|
+
- `Team`
|
|
38
|
+
|
|
39
|
+
## Quickstart
|
|
40
|
+
|
|
41
|
+
To get started you can import the class that represents the data you're searching for.
|
|
42
|
+
|
|
43
|
+
```{python}
|
|
44
|
+
from nbastatpy.player import Player
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Then you build a player using either an ID from stats.nba.com or the player's name. When you're building the player object you can add additional search data like season, data format, or playoffs vs. regular season.
|
|
48
|
+
|
|
49
|
+
```{python}
|
|
50
|
+
player = Player(
|
|
51
|
+
"Giannis",
|
|
52
|
+
season="2020",
|
|
53
|
+
playoffs=True,
|
|
54
|
+
permode="PerGame"
|
|
55
|
+
)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Once you have the player object, you can get different datasets based on the criteria. For instance, you can get the awards the player has won by doing the following:
|
|
59
|
+
|
|
60
|
+
```{python}
|
|
61
|
+
player.get_awards()
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
This returns a pandas dataframe with the awards won by the player each year.
|
|
65
|
+
|
|
66
|
+
There are a lot of endpoints and various arguments for more complex queries like tracking and synergy datasets.
|
|
67
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# NBAStatPy
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This is an easy-to-use wrapper for the `nba_api` package. The goal is to be able to easily access and find data for a player, game, team, or season.
|
|
6
|
+
|
|
7
|
+
The data is accessed through a class based on how you're searching for it. A quickstart example is shown below. Currently there are 4 classes:
|
|
8
|
+
|
|
9
|
+
- `Game`
|
|
10
|
+
- `Player`
|
|
11
|
+
- `Season`
|
|
12
|
+
- `Team`
|
|
13
|
+
|
|
14
|
+
## Quickstart
|
|
15
|
+
|
|
16
|
+
To get started you can import the class that represents the data you're searching for.
|
|
17
|
+
|
|
18
|
+
```{python}
|
|
19
|
+
from nbastatpy.player import Player
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Then you build a player using either an ID from stats.nba.com or the player's name. When you're building the player object you can add additional search data like season, data format, or playoffs vs. regular season.
|
|
23
|
+
|
|
24
|
+
```{python}
|
|
25
|
+
player = Player(
|
|
26
|
+
"Giannis",
|
|
27
|
+
season="2020",
|
|
28
|
+
playoffs=True,
|
|
29
|
+
permode="PerGame"
|
|
30
|
+
)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Once you have the player object, you can get different datasets based on the criteria. For instance, you can get the awards the player has won by doing the following:
|
|
34
|
+
|
|
35
|
+
```{python}
|
|
36
|
+
player.get_awards()
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
This returns a pandas dataframe with the awards won by the player each year.
|
|
40
|
+
|
|
41
|
+
There are a lot of endpoints and various arguments for more complex queries like tracking and synergy datasets.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "nbastatpy"
|
|
3
|
+
version = "0.1.6"
|
|
4
|
+
description = "An easy-to-use wrapper for nba_api to easily find data for a player, game, team, or season"
|
|
5
|
+
authors = []
|
|
6
|
+
maintainers = ["Anthony Berghammer <aberghammer.analytics@gmail.com>"]
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
repository = "https://github.com/aberghammer-analytics/NBAStatPy"
|
|
9
|
+
documentation = "https://github.com/aberghammer-analytics/NBAStatPy/blob/main/README.md"
|
|
10
|
+
keywords = ["basketball", "data", "nba", "sports", "stats"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Intended Audience :: Science/Research",
|
|
13
|
+
"License :: OSI Approved :: MIT License",
|
|
14
|
+
]
|
|
15
|
+
exclude = [
|
|
16
|
+
".scratch/",
|
|
17
|
+
".venv/",
|
|
18
|
+
".vscode",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[tool.poetry.dependencies]
|
|
22
|
+
python = "^3.10"
|
|
23
|
+
pandas = "^2.2.2"
|
|
24
|
+
nba_api = "^1.4.1"
|
|
25
|
+
pillow = "^10.3.0"
|
|
26
|
+
requests = "^2.31.0"
|
|
27
|
+
loguru = "^0.7.2"
|
|
28
|
+
rich = "^13.7.1"
|
|
29
|
+
bs4 = "^0.0.2"
|
|
30
|
+
|
|
31
|
+
[tool.poetry.group.dev.dependencies]
|
|
32
|
+
black = "^24.4.2"
|
|
33
|
+
|
|
34
|
+
[build-system]
|
|
35
|
+
requires = ["poetry-core"]
|
|
36
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
name = "nbastatpy"
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
import nba_api.stats.endpoints as nba
|
|
4
|
+
import pandas as pd
|
|
5
|
+
|
|
6
|
+
from nbastatpy.utils import Formatter
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Game:
|
|
10
|
+
def __init__(self, game_id: str):
|
|
11
|
+
"""This represents a game. Given an ID, you can get boxscore (and other) information through one of the 'get' methods
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
game_id (str): string with 10 digits
|
|
15
|
+
"""
|
|
16
|
+
self.game_id = Formatter.format_game_id(game_id)
|
|
17
|
+
|
|
18
|
+
def get_boxscore(self) -> List[pd.DataFrame]:
|
|
19
|
+
"""Gets traditional boxscore
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
List[pd.DataFrame]: list of dataframes (players, starters/bench, team)
|
|
23
|
+
"""
|
|
24
|
+
self.boxscore = nba.BoxScoreTraditionalV3(self.game_id).get_data_frames()
|
|
25
|
+
return self.boxscore
|
|
26
|
+
|
|
27
|
+
def get_advanced(self):
|
|
28
|
+
"""
|
|
29
|
+
Retrieves the advanced box score data for the game.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
pandas.DataFrame: The advanced box score data for the game.
|
|
33
|
+
"""
|
|
34
|
+
self.adv_box = nba.BoxScoreAdvancedV3(self.game_id).get_data_frames()
|
|
35
|
+
return self.adv_box
|
|
36
|
+
|
|
37
|
+
def get_defense(self):
|
|
38
|
+
"""
|
|
39
|
+
Retrieves the defensive statistics for the game.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
def_box (pandas.DataFrame): DataFrame containing the defensive statistics.
|
|
43
|
+
"""
|
|
44
|
+
self.def_box = nba.BoxScoreDefensiveV2(self.game_id).get_data_frames()
|
|
45
|
+
return self.def_box
|
|
46
|
+
|
|
47
|
+
def get_four_factors(self):
|
|
48
|
+
"""
|
|
49
|
+
Retrieves the four factors data for the game.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
pandas.DataFrame: The four factors data for the game.
|
|
53
|
+
"""
|
|
54
|
+
self.four_factors = nba.BoxScoreFourFactorsV3(self.game_id).get_data_frames()
|
|
55
|
+
return self.four_factors
|
|
56
|
+
|
|
57
|
+
def get_hustle(self) -> List[pd.DataFrame]:
|
|
58
|
+
"""Gets hustle data for a given game
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
List[pd.DataFrame]: list of two dataframes (players, teams)
|
|
62
|
+
"""
|
|
63
|
+
self.hustle = nba.BoxScoreHustleV2(self.game_id).get_data_frames()
|
|
64
|
+
return self.hustle
|
|
65
|
+
|
|
66
|
+
def get_matchups(self):
|
|
67
|
+
"""
|
|
68
|
+
Retrieves the matchups for the game.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
pandas.DataFrame: The matchups data for the game.
|
|
72
|
+
"""
|
|
73
|
+
self.matchups = nba.BoxScoreMatchupsV3(self.game_id).get_data_frames()
|
|
74
|
+
return self.matchups
|
|
75
|
+
|
|
76
|
+
def get_misc(self):
|
|
77
|
+
"""
|
|
78
|
+
Retrieves miscellaneous box score data for the game.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
pandas.DataFrame: The miscellaneous box score data.
|
|
82
|
+
"""
|
|
83
|
+
self.misc = nba.BoxScoreMiscV3(self.game_id).get_data_frames()
|
|
84
|
+
return self.misc
|
|
85
|
+
|
|
86
|
+
def get_scoring(self):
|
|
87
|
+
"""
|
|
88
|
+
Retrieves the scoring data for the game.
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
pandas.DataFrame: The scoring data for the game.
|
|
92
|
+
"""
|
|
93
|
+
self.scoring = nba.BoxScoreScoringV3(self.game_id).get_data_frames()
|
|
94
|
+
return self.scoring
|
|
95
|
+
|
|
96
|
+
def get_usage(self) -> List[pd.DataFrame]:
|
|
97
|
+
"""Gets usage data for a given game
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
List[pd.DataFrame]: list of two dataframes (players, teams)
|
|
101
|
+
"""
|
|
102
|
+
self.usage = nba.BoxScoreUsageV3(self.game_id).get_data_frames()
|
|
103
|
+
return self.usage
|
|
104
|
+
|
|
105
|
+
def get_playertrack(self):
|
|
106
|
+
"""
|
|
107
|
+
Retrieves the player tracking data for the game.
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
playertrack (pandas.DataFrame): The player tracking data for the game.
|
|
111
|
+
"""
|
|
112
|
+
self.playertrack = nba.BoxScorePlayerTrackV3(self.game_id).get_data_frames()
|
|
113
|
+
return self.playertrack
|
|
114
|
+
|
|
115
|
+
def get_rotations(self):
|
|
116
|
+
"""
|
|
117
|
+
Retrieves the rotations data for the game.
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
pandas.DataFrame: The rotations data for the game.
|
|
121
|
+
"""
|
|
122
|
+
self.rotations = pd.concat(
|
|
123
|
+
nba.GameRotation(game_id=self.game_id).get_data_frames()
|
|
124
|
+
)
|
|
125
|
+
return self.rotations
|
|
126
|
+
|
|
127
|
+
def get_playbyplay(self) -> pd.DataFrame:
|
|
128
|
+
"""
|
|
129
|
+
Retrieves the play-by-play data for the game.
|
|
130
|
+
|
|
131
|
+
Returns:
|
|
132
|
+
pd.DataFrame: The play-by-play data as a pandas DataFrame.
|
|
133
|
+
"""
|
|
134
|
+
self.playbyplay = nba.PlayByPlayV3(self.game_id).get_data_frames()[0]
|
|
135
|
+
return self.playbyplay
|
|
136
|
+
|
|
137
|
+
def get_win_probability(self) -> pd.DataFrame:
|
|
138
|
+
"""
|
|
139
|
+
Retrieves the win probability data for the game.
|
|
140
|
+
|
|
141
|
+
Returns:
|
|
142
|
+
pd.DataFrame: The win probability data as a pandas DataFrame.
|
|
143
|
+
"""
|
|
144
|
+
self.win_probability = nba.WinProbabilityPBP(
|
|
145
|
+
game_id=self.game_id
|
|
146
|
+
).get_data_frames()[0]
|
|
147
|
+
return self.win_probability
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
if __name__ == "__main__":
|
|
151
|
+
GAME_ID = "0022301148"
|
|
152
|
+
game = Game(game_id=GAME_ID)
|
|
153
|
+
print(game.get_win_probability())
|