crawlora-nba 0.1.1__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.
- crawlora_nba-0.1.1/LICENSE +21 -0
- crawlora_nba-0.1.1/PKG-INFO +175 -0
- crawlora_nba-0.1.1/README.md +151 -0
- crawlora_nba-0.1.1/crawlora_nba/__init__.py +18 -0
- crawlora_nba-0.1.1/crawlora_nba/__init__.pyi +10 -0
- crawlora_nba-0.1.1/crawlora_nba/_pagination.py +44 -0
- crawlora_nba-0.1.1/crawlora_nba/_transport_sync.py +114 -0
- crawlora_nba-0.1.1/crawlora_nba/async_client.py +321 -0
- crawlora_nba-0.1.1/crawlora_nba/client.py +671 -0
- crawlora_nba-0.1.1/crawlora_nba/operations.py +1528 -0
- crawlora_nba-0.1.1/crawlora_nba/platform.py +857 -0
- crawlora_nba-0.1.1/crawlora_nba/platform.pyi +6748 -0
- crawlora_nba-0.1.1/crawlora_nba/py.typed +0 -0
- crawlora_nba-0.1.1/crawlora_nba.egg-info/PKG-INFO +175 -0
- crawlora_nba-0.1.1/crawlora_nba.egg-info/SOURCES.txt +20 -0
- crawlora_nba-0.1.1/crawlora_nba.egg-info/dependency_links.txt +1 -0
- crawlora_nba-0.1.1/crawlora_nba.egg-info/requires.txt +10 -0
- crawlora_nba-0.1.1/crawlora_nba.egg-info/top_level.txt +1 -0
- crawlora_nba-0.1.1/pyproject.toml +36 -0
- crawlora_nba-0.1.1/setup.cfg +4 -0
- crawlora_nba-0.1.1/tests/test_package.py +87 -0
- crawlora_nba-0.1.1/tests/test_types.py +89 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Crawlora
|
|
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.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: crawlora-nba
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Crawlora NBA API client with 70 endpoints for games, standings, player and team statistics, play-by-play, and dashboards
|
|
5
|
+
Author: Crawlora
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://crawlora.net/?utm_source=pypi&utm_medium=referral&utm_campaign=platform-clients&utm_content=nba-python-homepage
|
|
8
|
+
Project-URL: Documentation, https://crawlora.net/docs?utm_source=pypi&utm_medium=referral&utm_campaign=platform-clients&utm_content=nba-python-api-docs
|
|
9
|
+
Project-URL: Repository, https://github.com/Crawlora-org/crawlora-nba
|
|
10
|
+
Keywords: crawlora,api-client,sdk,web-scraping,scraping-api,nba,nba-api,nba-scraper,nba-data,nba-games,nba-standings,nba-player-team-statistics,nba-play-play,nba-dashboards
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Typing :: Typed
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: typing-extensions>=4.7; python_version < "3.11"
|
|
18
|
+
Provides-Extra: async
|
|
19
|
+
Requires-Dist: httpx>=0.27; extra == "async"
|
|
20
|
+
Provides-Extra: test
|
|
21
|
+
Requires-Dist: mypy>=1.11; extra == "test"
|
|
22
|
+
Requires-Dist: pytest>=8; extra == "test"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# crawlora-nba — NBA API client for Python
|
|
26
|
+
|
|
27
|
+
Python client for Crawlora's hosted NBA API. It exposes 70 API endpoints covering games, standings, player and team statistics, play-by-play, and dashboards. Requests go to [Crawlora](https://crawlora.net/?utm_source=pypi&utm_medium=referral&utm_campaign=platform-clients&utm_content=nba-python-homepage); the package does not run a browser or scrape
|
|
28
|
+
NBA locally. A Crawlora account and `CRAWLORA_API_KEY` are required,
|
|
29
|
+
and API use is billed under your Crawlora account. Crawlora is independent from and not endorsed by
|
|
30
|
+
NBA or its owners.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
python -m pip install crawlora-nba
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Get an API key
|
|
39
|
+
|
|
40
|
+
Create an account at [crawlora.net](https://crawlora.net/signup?utm_source=pypi&utm_medium=referral&utm_campaign=platform-clients&utm_content=nba-python-signup), then open the [Crawlora console](https://crawlora.net/app?utm_source=pypi&utm_medium=referral&utm_campaign=platform-clients&utm_content=nba-python-console) for API-key setup. Set your key in the shell before running the client:
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
export CRAWLORA_API_KEY="your-crawlora-api-key"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Use
|
|
47
|
+
|
|
48
|
+
Save this example as `example.py`, then run `python example.py` after installing the package and setting your API key.
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
import os
|
|
52
|
+
|
|
53
|
+
from crawlora_nba import NBAClient
|
|
54
|
+
|
|
55
|
+
api_key = os.environ.get("CRAWLORA_API_KEY")
|
|
56
|
+
if not api_key:
|
|
57
|
+
raise RuntimeError("Set CRAWLORA_API_KEY before running this example.")
|
|
58
|
+
|
|
59
|
+
with NBAClient(api_key=api_key) as client:
|
|
60
|
+
result_1 = client.games()
|
|
61
|
+
print(result_1)
|
|
62
|
+
result_2 = client.enums()
|
|
63
|
+
print(result_2)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The package also exports `Client` as an alias for `NBAClient`. Operation
|
|
67
|
+
methods are available directly in snake_case and through the `nba`
|
|
68
|
+
group. The async package client is `AsyncNBAClient`; see the [online
|
|
69
|
+
endpoint and parameter reference](https://github.com/Crawlora-org/crawlora-nba/blob/main/docs/usage.md) and [runnable example](https://github.com/Crawlora-org/crawlora-nba/blob/main/examples/python.py).
|
|
70
|
+
|
|
71
|
+
### Async usage
|
|
72
|
+
|
|
73
|
+
The package also exports `AsyncClient` for asynchronous requests:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
import asyncio
|
|
77
|
+
import os
|
|
78
|
+
|
|
79
|
+
from crawlora_nba import AsyncClient
|
|
80
|
+
|
|
81
|
+
async def main():
|
|
82
|
+
api_key = os.environ.get("CRAWLORA_API_KEY")
|
|
83
|
+
if not api_key:
|
|
84
|
+
raise RuntimeError("Set CRAWLORA_API_KEY before running this example.")
|
|
85
|
+
async with AsyncClient(api_key=api_key) as client:
|
|
86
|
+
result_1 = await client.games()
|
|
87
|
+
print(result_1)
|
|
88
|
+
|
|
89
|
+
asyncio.run(main())
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
See the [runnable example](https://github.com/Crawlora-org/crawlora-nba/blob/main/examples/python.py) for a complete usage example.
|
|
93
|
+
|
|
94
|
+
## Supported NBA API endpoints
|
|
95
|
+
|
|
96
|
+
This package exposes every route below through direct snake_case methods and the `nba` group. See the [endpoint and parameter reference](https://github.com/Crawlora-org/crawlora-nba/blob/main/docs/usage.md) for complete input details.
|
|
97
|
+
|
|
98
|
+
| Method | Endpoint | API operation | Description |
|
|
99
|
+
| --- | --- | --- | --- |
|
|
100
|
+
| `GET` | `/nba/box-score` | `nba-box-score` | NBA traditional box score for one game |
|
|
101
|
+
| `GET` | `/nba/box-score-advanced` | `nba-box-score-advanced` | NBA advanced box score for one game |
|
|
102
|
+
| `GET` | `/nba/box-score-defensive` | `nba-box-score-defensive` | NBA defensive box score |
|
|
103
|
+
| `GET` | `/nba/box-score-four-factors` | `nba-box-score-four-factors` | NBA four-factors box score for one game |
|
|
104
|
+
| `GET` | `/nba/box-score-misc` | `nba-box-score-misc` | NBA miscellaneous box score for one game |
|
|
105
|
+
| `GET` | `/nba/box-score-player-track` | `nba-box-score-player-track` | NBA player-tracking box score for one game |
|
|
106
|
+
| `GET` | `/nba/box-score-scoring` | `nba-box-score-scoring` | NBA scoring-distribution box score for one game |
|
|
107
|
+
| `GET` | `/nba/box-score-summary` | `nba-box-score-summary` | Returns the game summary tables for one game: the game summary itself plus the other summary result sets the upstream returns (line scores and officials among them) |
|
|
108
|
+
| `GET` | `/nba/box-score-usage` | `nba-box-score-usage` | NBA usage box score for one game |
|
|
109
|
+
| `GET` | `/nba/common-all-players` | `nba-common-all-players` | NBA league-wide player listing for a season |
|
|
110
|
+
| `GET` | `/nba/draft-combine-anthro` | `nba-draft-combine-anthro` | NBA draft combine anthropometric measurements |
|
|
111
|
+
| `GET` | `/nba/enums` | `nba-enums` | List the pinned NBA request enum values |
|
|
112
|
+
| `GET` | `/nba/franchise-history` | `nba-franchise-history` | NBA franchise history, including defunct teams |
|
|
113
|
+
| `GET` | `/nba/game-detail` | `nba-game-detail` | NBA game summary detail from nba.com |
|
|
114
|
+
| `GET` | `/nba/games` | `nba-games` | Current NBA games from nba.com's own page state |
|
|
115
|
+
| `GET` | `/nba/homepage-leaders` | `nba-homepage-leaders` | NBA homepage leader board |
|
|
116
|
+
| `GET` | `/nba/homepage-v2` | `nba-homepage-v2` | Returns the homepagev2 leader board for one stat type, scope and subject |
|
|
117
|
+
| `GET` | `/nba/hustle-player` | `nba-hustle-player` | Returns the league's player hustle table: contested shots, deflections, charges drawn, screen assists and points, loose balls recovered and box-outs, one row per player |
|
|
118
|
+
| `GET` | `/nba/hustle-stats` | `nba-hustle-stats` | NBA hustle statistics for one game |
|
|
119
|
+
| `GET` | `/nba/hustle-team` | `nba-hustle-team` | Returns the league's team hustle table: contested shots, deflections, charges drawn, screen assists and points, loose balls recovered and box-outs |
|
|
120
|
+
| `GET` | `/nba/league-game-log` | `nba-league-game-log` | NBA game log for a season, by team or by player |
|
|
121
|
+
| `GET` | `/nba/lineup-shot-chart` | `nba-lineup-shot-chart` | Returns the shot chart for one team's five-man lineups: one row per lineup shot with the lineup id, the game, the shooter, the period, action and shot type, the zone, distance, court coordinates and the made flag |
|
|
122
|
+
| `GET` | `/nba/lineups` | `nba-lineups` | NBA lineup dashboard |
|
|
123
|
+
| `GET` | `/nba/news` | `nba-news` | NBA news articles from nba.com |
|
|
124
|
+
| `GET` | `/nba/opp-pt-shot` | `nba-opp-pt-shot` | Returns the league's opponent shooting table: one row per team with the shooting it allows, split overall and from three |
|
|
125
|
+
| `GET` | `/nba/play-by-play` | `nba-play-by-play` | NBA play-by-play for one game |
|
|
126
|
+
| `GET` | `/nba/player-awards` | `nba-player-awards` | NBA player award history |
|
|
127
|
+
| `GET` | `/nba/player-bio-stats` | `nba-player-bio-stats` | NBA league bio table |
|
|
128
|
+
| `GET` | `/nba/player-career-stats` | `nba-player-career-stats` | NBA player season-by-season and career statistics |
|
|
129
|
+
| `GET` | `/nba/player-clutch` | `nba-player-clutch` | Returns the league's clutch player table for one clutch window and score margin: the players' clutch shooting and counting stats |
|
|
130
|
+
| `GET` | `/nba/player-compare` | `nba-player-compare` | NBA two-sided player comparison |
|
|
131
|
+
| `GET` | `/nba/player-dash-by-clutch` | `nba-player-dash-by-clutch` | Returns one player's by clutch splits as several result sets |
|
|
132
|
+
| `GET` | `/nba/player-dash-by-game-splits` | `nba-player-dash-by-game-splits` | Returns one player's by game splits splits as several result sets |
|
|
133
|
+
| `GET` | `/nba/player-dash-by-last-n-games` | `nba-player-dash-by-last-n-games` | Returns one player's by last n games splits as several result sets |
|
|
134
|
+
| `GET` | `/nba/player-dash-by-opponent` | `nba-player-dash-by-opponent` | Returns one player's by opponent splits as several result sets |
|
|
135
|
+
| `GET` | `/nba/player-dash-pt-pass` | `nba-player-dash-pt-pass` | NBA player passing dashboard |
|
|
136
|
+
| `GET` | `/nba/player-dash-pt-reb` | `nba-player-dash-pt-reb` | NBA player rebound dashboard |
|
|
137
|
+
| `GET` | `/nba/player-dash-pt-shots` | `nba-player-dash-pt-shots` | NBA player tracking shot dashboard |
|
|
138
|
+
| `GET` | `/nba/player-game-logs` | `nba-player-game-logs` | Returns one player's game log for a season, one row per game with the player's box-score line |
|
|
139
|
+
| `GET` | `/nba/player-info` | `nba-player-info` | NBA player profile |
|
|
140
|
+
| `GET` | `/nba/player-profile-v2` | `nba-player-profile-v2` | Returns one player's full profile stat set: the season-by-season regular-season line, the career regular-season totals and the postseason equivalents |
|
|
141
|
+
| `GET` | `/nba/player-pt-shot` | `nba-player-pt-shot` | Returns the league's player shooting table: one row per player with the shooting line, split overall and from three |
|
|
142
|
+
| `GET` | `/nba/player-stats` | `nba-player-stats` | NBA league-wide player statistics table |
|
|
143
|
+
| `GET` | `/nba/player-streak-finder` | `nba-player-streak-finder` | Returns player game streaks for a season: the streak rows the upstream computes, one row per streak, with the player identity and streak totals |
|
|
144
|
+
| `GET` | `/nba/players` | `nba-players` | NBA player index: every player id for a season |
|
|
145
|
+
| `GET` | `/nba/playoff-picture` | `nba-playoff-picture` | NBA playoff picture by conference |
|
|
146
|
+
| `GET` | `/nba/playoff-series` | `nba-playoff-series` | NBA playoff series index |
|
|
147
|
+
| `GET` | `/nba/pt-defend` | `nba-pt-defend` | NBA defensive tracking dashboard |
|
|
148
|
+
| `GET` | `/nba/pt-stats` | `nba-pt-stats` | NBA player-tracking dashboard |
|
|
149
|
+
| `GET` | `/nba/scoreboard` | `nba-scoreboard` | NBA scoreboard for one game day |
|
|
150
|
+
| `GET` | `/nba/shot-chart` | `nba-shot-chart` | NBA shot chart |
|
|
151
|
+
| `GET` | `/nba/standings` | `nba-standings` | NBA standings for a season and season type |
|
|
152
|
+
| `GET` | `/nba/synergy-play-types` | `nba-synergy-play-types` | NBA synergy play-type dashboard |
|
|
153
|
+
| `GET` | `/nba/team-dash-by-clutch` | `nba-team-dash-by-clutch` | Returns one team's by clutch splits as several result sets |
|
|
154
|
+
| `GET` | `/nba/team-dash-by-game-splits` | `nba-team-dash-by-game-splits` | Returns one team's by game splits splits as several result sets |
|
|
155
|
+
| `GET` | `/nba/team-dash-by-last-n-games` | `nba-team-dash-by-last-n-games` | Returns one team's by last n games splits as several result sets |
|
|
156
|
+
| `GET` | `/nba/team-dash-by-opponent` | `nba-team-dash-by-opponent` | Returns one team's by opponent splits as several result sets |
|
|
157
|
+
| `GET` | `/nba/team-dash-pt-pass` | `nba-team-dash-pt-pass` | Returns one team's passing dashboard: the pass-type breakdowns the upstream computes for that team, as several result sets |
|
|
158
|
+
| `GET` | `/nba/team-dash-pt-reb` | `nba-team-dash-pt-reb` | NBA team rebound dashboard |
|
|
159
|
+
| `GET` | `/nba/team-dash-pt-shots` | `nba-team-dash-pt-shots` | Returns one team's tracking shot dashboard: the shot breakdowns the upstream computes for that team (by touch time and shot type), as several result sets |
|
|
160
|
+
| `GET` | `/nba/team-details` | `nba-team-details` | NBA franchise background, season history and awards |
|
|
161
|
+
| `GET` | `/nba/team-game-logs` | `nba-team-game-logs` | Returns one team's game log for a season, one row per game with the team's box-score line (field goals, threes, rebounds, assists, steals, blocks, turnovers, points and plus-minus) |
|
|
162
|
+
| `GET` | `/nba/team-info-common` | `nba-team-info-common` | Returns one team's identity and season summary: city, name, abbreviation, code, conference and division, the win/loss record and per-game team averages, plus the team's available seasons |
|
|
163
|
+
| `GET` | `/nba/team-on-off` | `nba-team-on-off` | Returns a team's on-court/off-court player splits: the on-court and off-court rows the upstream computes, with each player's minutes and rating impact |
|
|
164
|
+
| `GET` | `/nba/team-pt-shot` | `nba-team-pt-shot` | Returns the league's team shooting table: one row per team with the shooting line, split overall and from three |
|
|
165
|
+
| `GET` | `/nba/team-roster` | `nba-team-roster` | NBA team roster for a season |
|
|
166
|
+
| `GET` | `/nba/team-shot-locations` | `nba-team-shot-locations` | NBA team shot-location dashboard |
|
|
167
|
+
| `GET` | `/nba/team-stats` | `nba-team-stats` | NBA league-wide team statistics table |
|
|
168
|
+
| `GET` | `/nba/team-stats-leaders` | `nba-team-stats-leaders` | NBA league leaders for one statistical category |
|
|
169
|
+
| `GET` | `/nba/team-years` | `nba-team-years` | Returns every franchise and the range of seasons it has played, one row per team |
|
|
170
|
+
|
|
171
|
+
## Configuration
|
|
172
|
+
|
|
173
|
+
Pass your key through `api_key` or read `CRAWLORA_API_KEY` from the environment.
|
|
174
|
+
Keep credentials out of source control and logs. Requests go to Crawlora's
|
|
175
|
+
hosted API.
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# crawlora-nba — NBA API client for Python
|
|
2
|
+
|
|
3
|
+
Python client for Crawlora's hosted NBA API. It exposes 70 API endpoints covering games, standings, player and team statistics, play-by-play, and dashboards. Requests go to [Crawlora](https://crawlora.net/?utm_source=pypi&utm_medium=referral&utm_campaign=platform-clients&utm_content=nba-python-homepage); the package does not run a browser or scrape
|
|
4
|
+
NBA locally. A Crawlora account and `CRAWLORA_API_KEY` are required,
|
|
5
|
+
and API use is billed under your Crawlora account. Crawlora is independent from and not endorsed by
|
|
6
|
+
NBA or its owners.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
python -m pip install crawlora-nba
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Get an API key
|
|
15
|
+
|
|
16
|
+
Create an account at [crawlora.net](https://crawlora.net/signup?utm_source=pypi&utm_medium=referral&utm_campaign=platform-clients&utm_content=nba-python-signup), then open the [Crawlora console](https://crawlora.net/app?utm_source=pypi&utm_medium=referral&utm_campaign=platform-clients&utm_content=nba-python-console) for API-key setup. Set your key in the shell before running the client:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
export CRAWLORA_API_KEY="your-crawlora-api-key"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Use
|
|
23
|
+
|
|
24
|
+
Save this example as `example.py`, then run `python example.py` after installing the package and setting your API key.
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
import os
|
|
28
|
+
|
|
29
|
+
from crawlora_nba import NBAClient
|
|
30
|
+
|
|
31
|
+
api_key = os.environ.get("CRAWLORA_API_KEY")
|
|
32
|
+
if not api_key:
|
|
33
|
+
raise RuntimeError("Set CRAWLORA_API_KEY before running this example.")
|
|
34
|
+
|
|
35
|
+
with NBAClient(api_key=api_key) as client:
|
|
36
|
+
result_1 = client.games()
|
|
37
|
+
print(result_1)
|
|
38
|
+
result_2 = client.enums()
|
|
39
|
+
print(result_2)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The package also exports `Client` as an alias for `NBAClient`. Operation
|
|
43
|
+
methods are available directly in snake_case and through the `nba`
|
|
44
|
+
group. The async package client is `AsyncNBAClient`; see the [online
|
|
45
|
+
endpoint and parameter reference](https://github.com/Crawlora-org/crawlora-nba/blob/main/docs/usage.md) and [runnable example](https://github.com/Crawlora-org/crawlora-nba/blob/main/examples/python.py).
|
|
46
|
+
|
|
47
|
+
### Async usage
|
|
48
|
+
|
|
49
|
+
The package also exports `AsyncClient` for asynchronous requests:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import asyncio
|
|
53
|
+
import os
|
|
54
|
+
|
|
55
|
+
from crawlora_nba import AsyncClient
|
|
56
|
+
|
|
57
|
+
async def main():
|
|
58
|
+
api_key = os.environ.get("CRAWLORA_API_KEY")
|
|
59
|
+
if not api_key:
|
|
60
|
+
raise RuntimeError("Set CRAWLORA_API_KEY before running this example.")
|
|
61
|
+
async with AsyncClient(api_key=api_key) as client:
|
|
62
|
+
result_1 = await client.games()
|
|
63
|
+
print(result_1)
|
|
64
|
+
|
|
65
|
+
asyncio.run(main())
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
See the [runnable example](https://github.com/Crawlora-org/crawlora-nba/blob/main/examples/python.py) for a complete usage example.
|
|
69
|
+
|
|
70
|
+
## Supported NBA API endpoints
|
|
71
|
+
|
|
72
|
+
This package exposes every route below through direct snake_case methods and the `nba` group. See the [endpoint and parameter reference](https://github.com/Crawlora-org/crawlora-nba/blob/main/docs/usage.md) for complete input details.
|
|
73
|
+
|
|
74
|
+
| Method | Endpoint | API operation | Description |
|
|
75
|
+
| --- | --- | --- | --- |
|
|
76
|
+
| `GET` | `/nba/box-score` | `nba-box-score` | NBA traditional box score for one game |
|
|
77
|
+
| `GET` | `/nba/box-score-advanced` | `nba-box-score-advanced` | NBA advanced box score for one game |
|
|
78
|
+
| `GET` | `/nba/box-score-defensive` | `nba-box-score-defensive` | NBA defensive box score |
|
|
79
|
+
| `GET` | `/nba/box-score-four-factors` | `nba-box-score-four-factors` | NBA four-factors box score for one game |
|
|
80
|
+
| `GET` | `/nba/box-score-misc` | `nba-box-score-misc` | NBA miscellaneous box score for one game |
|
|
81
|
+
| `GET` | `/nba/box-score-player-track` | `nba-box-score-player-track` | NBA player-tracking box score for one game |
|
|
82
|
+
| `GET` | `/nba/box-score-scoring` | `nba-box-score-scoring` | NBA scoring-distribution box score for one game |
|
|
83
|
+
| `GET` | `/nba/box-score-summary` | `nba-box-score-summary` | Returns the game summary tables for one game: the game summary itself plus the other summary result sets the upstream returns (line scores and officials among them) |
|
|
84
|
+
| `GET` | `/nba/box-score-usage` | `nba-box-score-usage` | NBA usage box score for one game |
|
|
85
|
+
| `GET` | `/nba/common-all-players` | `nba-common-all-players` | NBA league-wide player listing for a season |
|
|
86
|
+
| `GET` | `/nba/draft-combine-anthro` | `nba-draft-combine-anthro` | NBA draft combine anthropometric measurements |
|
|
87
|
+
| `GET` | `/nba/enums` | `nba-enums` | List the pinned NBA request enum values |
|
|
88
|
+
| `GET` | `/nba/franchise-history` | `nba-franchise-history` | NBA franchise history, including defunct teams |
|
|
89
|
+
| `GET` | `/nba/game-detail` | `nba-game-detail` | NBA game summary detail from nba.com |
|
|
90
|
+
| `GET` | `/nba/games` | `nba-games` | Current NBA games from nba.com's own page state |
|
|
91
|
+
| `GET` | `/nba/homepage-leaders` | `nba-homepage-leaders` | NBA homepage leader board |
|
|
92
|
+
| `GET` | `/nba/homepage-v2` | `nba-homepage-v2` | Returns the homepagev2 leader board for one stat type, scope and subject |
|
|
93
|
+
| `GET` | `/nba/hustle-player` | `nba-hustle-player` | Returns the league's player hustle table: contested shots, deflections, charges drawn, screen assists and points, loose balls recovered and box-outs, one row per player |
|
|
94
|
+
| `GET` | `/nba/hustle-stats` | `nba-hustle-stats` | NBA hustle statistics for one game |
|
|
95
|
+
| `GET` | `/nba/hustle-team` | `nba-hustle-team` | Returns the league's team hustle table: contested shots, deflections, charges drawn, screen assists and points, loose balls recovered and box-outs |
|
|
96
|
+
| `GET` | `/nba/league-game-log` | `nba-league-game-log` | NBA game log for a season, by team or by player |
|
|
97
|
+
| `GET` | `/nba/lineup-shot-chart` | `nba-lineup-shot-chart` | Returns the shot chart for one team's five-man lineups: one row per lineup shot with the lineup id, the game, the shooter, the period, action and shot type, the zone, distance, court coordinates and the made flag |
|
|
98
|
+
| `GET` | `/nba/lineups` | `nba-lineups` | NBA lineup dashboard |
|
|
99
|
+
| `GET` | `/nba/news` | `nba-news` | NBA news articles from nba.com |
|
|
100
|
+
| `GET` | `/nba/opp-pt-shot` | `nba-opp-pt-shot` | Returns the league's opponent shooting table: one row per team with the shooting it allows, split overall and from three |
|
|
101
|
+
| `GET` | `/nba/play-by-play` | `nba-play-by-play` | NBA play-by-play for one game |
|
|
102
|
+
| `GET` | `/nba/player-awards` | `nba-player-awards` | NBA player award history |
|
|
103
|
+
| `GET` | `/nba/player-bio-stats` | `nba-player-bio-stats` | NBA league bio table |
|
|
104
|
+
| `GET` | `/nba/player-career-stats` | `nba-player-career-stats` | NBA player season-by-season and career statistics |
|
|
105
|
+
| `GET` | `/nba/player-clutch` | `nba-player-clutch` | Returns the league's clutch player table for one clutch window and score margin: the players' clutch shooting and counting stats |
|
|
106
|
+
| `GET` | `/nba/player-compare` | `nba-player-compare` | NBA two-sided player comparison |
|
|
107
|
+
| `GET` | `/nba/player-dash-by-clutch` | `nba-player-dash-by-clutch` | Returns one player's by clutch splits as several result sets |
|
|
108
|
+
| `GET` | `/nba/player-dash-by-game-splits` | `nba-player-dash-by-game-splits` | Returns one player's by game splits splits as several result sets |
|
|
109
|
+
| `GET` | `/nba/player-dash-by-last-n-games` | `nba-player-dash-by-last-n-games` | Returns one player's by last n games splits as several result sets |
|
|
110
|
+
| `GET` | `/nba/player-dash-by-opponent` | `nba-player-dash-by-opponent` | Returns one player's by opponent splits as several result sets |
|
|
111
|
+
| `GET` | `/nba/player-dash-pt-pass` | `nba-player-dash-pt-pass` | NBA player passing dashboard |
|
|
112
|
+
| `GET` | `/nba/player-dash-pt-reb` | `nba-player-dash-pt-reb` | NBA player rebound dashboard |
|
|
113
|
+
| `GET` | `/nba/player-dash-pt-shots` | `nba-player-dash-pt-shots` | NBA player tracking shot dashboard |
|
|
114
|
+
| `GET` | `/nba/player-game-logs` | `nba-player-game-logs` | Returns one player's game log for a season, one row per game with the player's box-score line |
|
|
115
|
+
| `GET` | `/nba/player-info` | `nba-player-info` | NBA player profile |
|
|
116
|
+
| `GET` | `/nba/player-profile-v2` | `nba-player-profile-v2` | Returns one player's full profile stat set: the season-by-season regular-season line, the career regular-season totals and the postseason equivalents |
|
|
117
|
+
| `GET` | `/nba/player-pt-shot` | `nba-player-pt-shot` | Returns the league's player shooting table: one row per player with the shooting line, split overall and from three |
|
|
118
|
+
| `GET` | `/nba/player-stats` | `nba-player-stats` | NBA league-wide player statistics table |
|
|
119
|
+
| `GET` | `/nba/player-streak-finder` | `nba-player-streak-finder` | Returns player game streaks for a season: the streak rows the upstream computes, one row per streak, with the player identity and streak totals |
|
|
120
|
+
| `GET` | `/nba/players` | `nba-players` | NBA player index: every player id for a season |
|
|
121
|
+
| `GET` | `/nba/playoff-picture` | `nba-playoff-picture` | NBA playoff picture by conference |
|
|
122
|
+
| `GET` | `/nba/playoff-series` | `nba-playoff-series` | NBA playoff series index |
|
|
123
|
+
| `GET` | `/nba/pt-defend` | `nba-pt-defend` | NBA defensive tracking dashboard |
|
|
124
|
+
| `GET` | `/nba/pt-stats` | `nba-pt-stats` | NBA player-tracking dashboard |
|
|
125
|
+
| `GET` | `/nba/scoreboard` | `nba-scoreboard` | NBA scoreboard for one game day |
|
|
126
|
+
| `GET` | `/nba/shot-chart` | `nba-shot-chart` | NBA shot chart |
|
|
127
|
+
| `GET` | `/nba/standings` | `nba-standings` | NBA standings for a season and season type |
|
|
128
|
+
| `GET` | `/nba/synergy-play-types` | `nba-synergy-play-types` | NBA synergy play-type dashboard |
|
|
129
|
+
| `GET` | `/nba/team-dash-by-clutch` | `nba-team-dash-by-clutch` | Returns one team's by clutch splits as several result sets |
|
|
130
|
+
| `GET` | `/nba/team-dash-by-game-splits` | `nba-team-dash-by-game-splits` | Returns one team's by game splits splits as several result sets |
|
|
131
|
+
| `GET` | `/nba/team-dash-by-last-n-games` | `nba-team-dash-by-last-n-games` | Returns one team's by last n games splits as several result sets |
|
|
132
|
+
| `GET` | `/nba/team-dash-by-opponent` | `nba-team-dash-by-opponent` | Returns one team's by opponent splits as several result sets |
|
|
133
|
+
| `GET` | `/nba/team-dash-pt-pass` | `nba-team-dash-pt-pass` | Returns one team's passing dashboard: the pass-type breakdowns the upstream computes for that team, as several result sets |
|
|
134
|
+
| `GET` | `/nba/team-dash-pt-reb` | `nba-team-dash-pt-reb` | NBA team rebound dashboard |
|
|
135
|
+
| `GET` | `/nba/team-dash-pt-shots` | `nba-team-dash-pt-shots` | Returns one team's tracking shot dashboard: the shot breakdowns the upstream computes for that team (by touch time and shot type), as several result sets |
|
|
136
|
+
| `GET` | `/nba/team-details` | `nba-team-details` | NBA franchise background, season history and awards |
|
|
137
|
+
| `GET` | `/nba/team-game-logs` | `nba-team-game-logs` | Returns one team's game log for a season, one row per game with the team's box-score line (field goals, threes, rebounds, assists, steals, blocks, turnovers, points and plus-minus) |
|
|
138
|
+
| `GET` | `/nba/team-info-common` | `nba-team-info-common` | Returns one team's identity and season summary: city, name, abbreviation, code, conference and division, the win/loss record and per-game team averages, plus the team's available seasons |
|
|
139
|
+
| `GET` | `/nba/team-on-off` | `nba-team-on-off` | Returns a team's on-court/off-court player splits: the on-court and off-court rows the upstream computes, with each player's minutes and rating impact |
|
|
140
|
+
| `GET` | `/nba/team-pt-shot` | `nba-team-pt-shot` | Returns the league's team shooting table: one row per team with the shooting line, split overall and from three |
|
|
141
|
+
| `GET` | `/nba/team-roster` | `nba-team-roster` | NBA team roster for a season |
|
|
142
|
+
| `GET` | `/nba/team-shot-locations` | `nba-team-shot-locations` | NBA team shot-location dashboard |
|
|
143
|
+
| `GET` | `/nba/team-stats` | `nba-team-stats` | NBA league-wide team statistics table |
|
|
144
|
+
| `GET` | `/nba/team-stats-leaders` | `nba-team-stats-leaders` | NBA league leaders for one statistical category |
|
|
145
|
+
| `GET` | `/nba/team-years` | `nba-team-years` | Returns every franchise and the range of seasons it has played, one row per team |
|
|
146
|
+
|
|
147
|
+
## Configuration
|
|
148
|
+
|
|
149
|
+
Pass your key through `api_key` or read `CRAWLORA_API_KEY` from the environment.
|
|
150
|
+
Keep credentials out of source control and logs. Requests go to Crawlora's
|
|
151
|
+
hosted API.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Typed NBA client for the Crawlora hosted API."""
|
|
2
|
+
|
|
3
|
+
from .platform import NBAClient, AsyncNBAClient
|
|
4
|
+
from .client import CrawloraClientError, CrawloraError, CrawloraNetworkError, CrawloraServerError
|
|
5
|
+
from .operations import OPERATION_COUNT, OPERATION_IDS, PLATFORM
|
|
6
|
+
|
|
7
|
+
Client = NBAClient
|
|
8
|
+
AsyncClient = AsyncNBAClient
|
|
9
|
+
__version__ = '0.1.1'
|
|
10
|
+
DISPLAY_NAME = 'NBA'
|
|
11
|
+
PLATFORM = 'nba'
|
|
12
|
+
CONTRACT_REVISION = 'sha256:343b4e2ca3bea9fd723ed7fa4522b82cbfcf68cc70aec065ce0692310568d3e9'
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"NBAClient", "AsyncNBAClient", "Client", "AsyncClient",
|
|
16
|
+
"CrawloraError", "CrawloraClientError", "CrawloraServerError", "CrawloraNetworkError",
|
|
17
|
+
"DISPLAY_NAME", "PLATFORM", "CONTRACT_REVISION", "OPERATION_COUNT", "OPERATION_IDS", "__version__",
|
|
18
|
+
]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from .platform import NBAClient as NBAClient
|
|
2
|
+
from .platform import AsyncNBAClient as AsyncNBAClient
|
|
3
|
+
Client = NBAClient
|
|
4
|
+
AsyncClient = AsyncNBAClient
|
|
5
|
+
from .client import CrawloraClientError as CrawloraClientError, CrawloraError as CrawloraError, CrawloraNetworkError as CrawloraNetworkError, CrawloraServerError as CrawloraServerError
|
|
6
|
+
from .operations import OPERATION_COUNT as OPERATION_COUNT, OPERATION_IDS as OPERATION_IDS, PLATFORM as PLATFORM
|
|
7
|
+
__version__: str
|
|
8
|
+
DISPLAY_NAME: str
|
|
9
|
+
CONTRACT_REVISION: str
|
|
10
|
+
__all__ = ['NBAClient', 'AsyncNBAClient', 'Client', 'AsyncClient', 'CrawloraError', 'CrawloraClientError', 'CrawloraServerError', 'CrawloraNetworkError', 'DISPLAY_NAME', 'PLATFORM', 'CONTRACT_REVISION', 'OPERATION_COUNT', 'OPERATION_IDS', '__version__']
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Shared pagination helpers used by the sync and async clients.
|
|
2
|
+
|
|
3
|
+
This module deliberately has no `.pyi` stub so type checkers read its inline
|
|
4
|
+
annotations directly (the `client.pyi` stub shadows `client.py`).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import Any, Mapping
|
|
10
|
+
|
|
11
|
+
PAGE_PARAM_NAMES = ("page", "offset")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def detect_page_param(operation: Mapping[str, Any]) -> str | None:
|
|
15
|
+
names = {parameter["name"] for parameter in operation.get("queryParams", [])}
|
|
16
|
+
for candidate in PAGE_PARAM_NAMES:
|
|
17
|
+
if candidate in names:
|
|
18
|
+
return candidate
|
|
19
|
+
return None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def page_is_empty(response: Any) -> bool:
|
|
23
|
+
data = response
|
|
24
|
+
if isinstance(response, Mapping) and "data" in response:
|
|
25
|
+
data = response["data"]
|
|
26
|
+
if data is None:
|
|
27
|
+
return True
|
|
28
|
+
if isinstance(data, (list, tuple, dict, str)):
|
|
29
|
+
return len(data) == 0
|
|
30
|
+
return not data
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def default_start(page_param: str) -> int:
|
|
34
|
+
return 0 if page_param == "offset" else 1
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def default_items(response: Any) -> list[Any]:
|
|
38
|
+
"""Default item extractor: the response's ``data`` list (Crawlora envelope),
|
|
39
|
+
or the response itself when it is already a list."""
|
|
40
|
+
if isinstance(response, Mapping) and isinstance(response.get("data"), list):
|
|
41
|
+
return list(response["data"])
|
|
42
|
+
if isinstance(response, list):
|
|
43
|
+
return list(response)
|
|
44
|
+
return []
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""Keep-alive HTTP transport for the synchronous client (standard library only).
|
|
2
|
+
|
|
3
|
+
Maintains a small pool of reusable connections per ``(scheme, host, port)`` so
|
|
4
|
+
the sync client avoids a fresh TCP + TLS handshake on every request. Each
|
|
5
|
+
request checks out its own connection, so the transport is safe to use from
|
|
6
|
+
multiple threads (e.g. under ``max_concurrency``). This module is stub-free so
|
|
7
|
+
type checkers read its inline annotations directly.
|
|
8
|
+
|
|
9
|
+
The transport returns a lightweight response object exposing ``status``,
|
|
10
|
+
``headers`` (a dict), and ``body`` (bytes) — the only fields the client reads.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import http.client
|
|
16
|
+
import threading
|
|
17
|
+
from dataclasses import dataclass
|
|
18
|
+
from typing import Any, Mapping
|
|
19
|
+
from urllib.parse import urlsplit
|
|
20
|
+
from urllib.request import Request
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _title_case(name: str) -> str:
|
|
24
|
+
return "-".join(part.capitalize() for part in name.split("-"))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass(frozen=True)
|
|
28
|
+
class _PooledResponse:
|
|
29
|
+
status: int
|
|
30
|
+
headers: Mapping[str, str]
|
|
31
|
+
body: bytes
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class KeepAliveTransport:
|
|
35
|
+
"""Connection-pooling transport. Drop-in for the urlopen transport: callable
|
|
36
|
+
as ``transport(request, timeout) -> response``."""
|
|
37
|
+
|
|
38
|
+
def __init__(self, max_per_host: int = 8) -> None:
|
|
39
|
+
self._lock = threading.Lock()
|
|
40
|
+
self._pools: dict[tuple, list[http.client.HTTPConnection]] = {}
|
|
41
|
+
self._max_per_host = max_per_host
|
|
42
|
+
|
|
43
|
+
def __call__(self, request: Request, timeout: float) -> _PooledResponse:
|
|
44
|
+
parts = urlsplit(request.full_url)
|
|
45
|
+
key = (parts.scheme, parts.hostname, parts.port)
|
|
46
|
+
path = parts.path or "/"
|
|
47
|
+
if parts.query:
|
|
48
|
+
path = f"{path}?{parts.query}"
|
|
49
|
+
method = request.get_method()
|
|
50
|
+
# Send canonical HTTP title-case header names (matching the urlopen
|
|
51
|
+
# transport's behavior), so receivers see e.g. "X-Api-Key".
|
|
52
|
+
headers = {_title_case(name): value for name, value in request.header_items()}
|
|
53
|
+
body = request.data
|
|
54
|
+
|
|
55
|
+
last_exc: Exception | None = None
|
|
56
|
+
for attempt in range(2):
|
|
57
|
+
conn = self._checkout(key, parts, timeout)
|
|
58
|
+
try:
|
|
59
|
+
conn.request(method, path, body=body, headers=headers)
|
|
60
|
+
response = conn.getresponse()
|
|
61
|
+
data = response.read()
|
|
62
|
+
result = _PooledResponse(response.status, dict(response.getheaders()), data)
|
|
63
|
+
except (http.client.HTTPException, ConnectionError, OSError) as exc:
|
|
64
|
+
# Likely a stale pooled connection the server already closed;
|
|
65
|
+
# discard it and retry once on a fresh connection.
|
|
66
|
+
last_exc = exc
|
|
67
|
+
self._close(conn)
|
|
68
|
+
if attempt == 1:
|
|
69
|
+
raise
|
|
70
|
+
continue
|
|
71
|
+
if response.will_close:
|
|
72
|
+
self._close(conn)
|
|
73
|
+
else:
|
|
74
|
+
self._checkin(key, conn)
|
|
75
|
+
return result
|
|
76
|
+
raise last_exc if last_exc else RuntimeError("keep-alive transport failed")
|
|
77
|
+
|
|
78
|
+
def close(self) -> None:
|
|
79
|
+
with self._lock:
|
|
80
|
+
pools = list(self._pools.values())
|
|
81
|
+
self._pools.clear()
|
|
82
|
+
for pool in pools:
|
|
83
|
+
for conn in pool:
|
|
84
|
+
self._close(conn)
|
|
85
|
+
|
|
86
|
+
def _checkout(self, key: tuple, parts: Any, timeout: float) -> http.client.HTTPConnection:
|
|
87
|
+
with self._lock:
|
|
88
|
+
pool = self._pools.get(key)
|
|
89
|
+
if pool:
|
|
90
|
+
conn = pool.pop()
|
|
91
|
+
conn.timeout = timeout
|
|
92
|
+
return conn
|
|
93
|
+
return self._new(parts, timeout)
|
|
94
|
+
|
|
95
|
+
def _checkin(self, key: tuple, conn: http.client.HTTPConnection) -> None:
|
|
96
|
+
with self._lock:
|
|
97
|
+
pool = self._pools.setdefault(key, [])
|
|
98
|
+
if len(pool) < self._max_per_host:
|
|
99
|
+
pool.append(conn)
|
|
100
|
+
return
|
|
101
|
+
self._close(conn)
|
|
102
|
+
|
|
103
|
+
@staticmethod
|
|
104
|
+
def _new(parts: Any, timeout: float) -> http.client.HTTPConnection:
|
|
105
|
+
if parts.scheme == "https":
|
|
106
|
+
return http.client.HTTPSConnection(parts.hostname, parts.port or 443, timeout=timeout)
|
|
107
|
+
return http.client.HTTPConnection(parts.hostname, parts.port or 80, timeout=timeout)
|
|
108
|
+
|
|
109
|
+
@staticmethod
|
|
110
|
+
def _close(conn: http.client.HTTPConnection) -> None:
|
|
111
|
+
try:
|
|
112
|
+
conn.close()
|
|
113
|
+
except Exception:
|
|
114
|
+
pass
|