crawlora-mlb 0.1.0__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_mlb-0.1.0/LICENSE +21 -0
- crawlora_mlb-0.1.0/PKG-INFO +171 -0
- crawlora_mlb-0.1.0/README.md +147 -0
- crawlora_mlb-0.1.0/crawlora_mlb/__init__.py +18 -0
- crawlora_mlb-0.1.0/crawlora_mlb/__init__.pyi +10 -0
- crawlora_mlb-0.1.0/crawlora_mlb/_pagination.py +44 -0
- crawlora_mlb-0.1.0/crawlora_mlb/_transport_sync.py +114 -0
- crawlora_mlb-0.1.0/crawlora_mlb/async_client.py +321 -0
- crawlora_mlb-0.1.0/crawlora_mlb/client.py +671 -0
- crawlora_mlb-0.1.0/crawlora_mlb/operations.py +5821 -0
- crawlora_mlb-0.1.0/crawlora_mlb/platform.py +809 -0
- crawlora_mlb-0.1.0/crawlora_mlb/platform.pyi +9474 -0
- crawlora_mlb-0.1.0/crawlora_mlb/py.typed +0 -0
- crawlora_mlb-0.1.0/crawlora_mlb.egg-info/PKG-INFO +171 -0
- crawlora_mlb-0.1.0/crawlora_mlb.egg-info/SOURCES.txt +20 -0
- crawlora_mlb-0.1.0/crawlora_mlb.egg-info/dependency_links.txt +1 -0
- crawlora_mlb-0.1.0/crawlora_mlb.egg-info/requires.txt +10 -0
- crawlora_mlb-0.1.0/crawlora_mlb.egg-info/top_level.txt +1 -0
- crawlora_mlb-0.1.0/pyproject.toml +36 -0
- crawlora_mlb-0.1.0/setup.cfg +4 -0
- crawlora_mlb-0.1.0/tests/test_package.py +87 -0
- crawlora_mlb-0.1.0/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,171 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: crawlora-mlb
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Crawlora MLB API client with 66 endpoints for game schedules and details, box scores, standings, player and team statistics, news, and league discovery
|
|
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=mlb-python-homepage
|
|
8
|
+
Project-URL: Documentation, https://crawlora.net/docs?utm_source=pypi&utm_medium=referral&utm_campaign=platform-clients&utm_content=mlb-python-api-docs
|
|
9
|
+
Project-URL: Repository, https://github.com/Crawlora-org/crawlora-mlb
|
|
10
|
+
Keywords: crawlora,api-client,sdk,web-scraping,scraping-api,mlb,mlb-api,mlb-scraper,mlb-data,mlb-game-schedules-details,mlb-box-scores,mlb-standings,mlb-player-team-statistics,mlb-news,mlb-league-discovery
|
|
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-mlb — MLB API client for Python
|
|
26
|
+
|
|
27
|
+
Python client for Crawlora's hosted MLB API. It exposes 66 API endpoints covering game schedules and details, box scores, standings, player and team statistics, news, and league discovery. Requests go to [Crawlora](https://crawlora.net/?utm_source=pypi&utm_medium=referral&utm_campaign=platform-clients&utm_content=mlb-python-homepage); the package does not run a browser or scrape
|
|
28
|
+
MLB 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
|
+
MLB or its owners.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
python -m pip install crawlora-mlb
|
|
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=mlb-python-signup), then open the [Crawlora console](https://crawlora.net/app?utm_source=pypi&utm_medium=referral&utm_campaign=platform-clients&utm_content=mlb-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_mlb import MLBClient
|
|
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 MLBClient(api_key=api_key) as client:
|
|
60
|
+
result_1 = client.discovery()
|
|
61
|
+
print(result_1)
|
|
62
|
+
result_2 = client.editorial_feed(slug='mlb')
|
|
63
|
+
print(result_2)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The package also exports `Client` as an alias for `MLBClient`. Operation
|
|
67
|
+
methods are available directly in snake_case and through the `mlb`
|
|
68
|
+
group. The async package client is `AsyncMLBClient`; see the [online
|
|
69
|
+
endpoint and parameter reference](https://github.com/Crawlora-org/crawlora-mlb/blob/main/docs/usage.md) and [runnable example](https://github.com/Crawlora-org/crawlora-mlb/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_mlb 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.discovery()
|
|
87
|
+
print(result_1)
|
|
88
|
+
|
|
89
|
+
asyncio.run(main())
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
See the [runnable example](https://github.com/Crawlora-org/crawlora-mlb/blob/main/examples/python.py) for a complete usage example.
|
|
93
|
+
|
|
94
|
+
## Supported MLB API endpoints
|
|
95
|
+
|
|
96
|
+
This package exposes every route below through direct snake_case methods and the `mlb` group. See the [endpoint and parameter reference](https://github.com/Crawlora-org/crawlora-mlb/blob/main/docs/usage.md) for complete input details.
|
|
97
|
+
|
|
98
|
+
| Method | Endpoint | API operation | Description |
|
|
99
|
+
| --- | --- | --- | --- |
|
|
100
|
+
| `GET` | `/mlb/discovery` | `mlb-discovery` | Discover MLB sections and Stats API values |
|
|
101
|
+
| `GET` | `/mlb/editorial-feed` | `mlb-editorial-feed` | Get an MLB.com editorial feed |
|
|
102
|
+
| `GET` | `/mlb/game` | `mlb-game` | Get an MLB game feed |
|
|
103
|
+
| `GET` | `/mlb/game-boxscore` | `mlb-game-boxscore` | Get an MLB player boxscore |
|
|
104
|
+
| `GET` | `/mlb/game-play-by-play` | `mlb-game-play-by-play` | Get MLB game play-by-play |
|
|
105
|
+
| `GET` | `/mlb/league-leaders` | `mlb-league-leaders` | Get MLB league leaders |
|
|
106
|
+
| `GET` | `/mlb/league-stats` | `mlb-league-stats` | Get ranked MLB league statistics |
|
|
107
|
+
| `GET` | `/mlb/player` | `mlb-player` | Get an MLB player |
|
|
108
|
+
| `GET` | `/mlb/player-stats` | `mlb-player-stats` | Get MLB player season statistics |
|
|
109
|
+
| `GET` | `/mlb/prospect-rankings` | `mlb-prospect-rankings` | Get MLB Pipeline curated prospect rankings |
|
|
110
|
+
| `GET` | `/mlb/prospect-stats` | `mlb-prospect-stats` | Get MLB Pipeline prospect statistics and rankings |
|
|
111
|
+
| `GET` | `/mlb/schedule` | `mlb-schedule` | Get the MLB schedule and scores |
|
|
112
|
+
| `GET` | `/mlb/search` | `mlb-search` | Search MLB players, teams, and content topics |
|
|
113
|
+
| `GET` | `/mlb/standings` | `mlb-standings` | Get MLB standings |
|
|
114
|
+
| `GET` | `/mlb/statcast-abs-challenges` | `mlb-statcast-abs-challenges` | Get Baseball Savant ABS challenge rankings |
|
|
115
|
+
| `GET` | `/mlb/statcast-active-spin` | `mlb-statcast-active-spin` | Get Baseball Savant Active Spin rows |
|
|
116
|
+
| `GET` | `/mlb/statcast-arm-angle` | `mlb-statcast-arm-angle` | Get Baseball Savant Pitcher Arm Angle rows |
|
|
117
|
+
| `GET` | `/mlb/statcast-arm-strength` | `mlb-statcast-arm-strength` | Get Baseball Savant Arm Strength leaderboard data |
|
|
118
|
+
| `GET` | `/mlb/statcast-arm-strength-player` | `mlb-statcast-arm-strength-player` | Get Baseball Savant player throw details |
|
|
119
|
+
| `GET` | `/mlb/statcast-arm-value` | `mlb-statcast-arm-value` | Get Baseball Savant Extra Bases Run Value leaderboard data |
|
|
120
|
+
| `GET` | `/mlb/statcast-arm-value-details` | `mlb-statcast-arm-value-details` | Get expanded Baseball Savant Arm Value player plays |
|
|
121
|
+
| `GET` | `/mlb/statcast-baserunning` | `mlb-statcast-baserunning` | Get Baseball Savant baserunning leaderboard tables |
|
|
122
|
+
| `GET` | `/mlb/statcast-bat-tracking` | `mlb-statcast-bat-tracking` | Get Baseball Savant bat-tracking rows |
|
|
123
|
+
| `GET` | `/mlb/statcast-batted-ball` | `mlb-statcast-batted-ball` | Get Baseball Savant Batted Ball Profile rows |
|
|
124
|
+
| `GET` | `/mlb/statcast-birthday-index` | `mlb-statcast-birthday-index` | Get Baseball Savant Sarah Langs Birthday Index rows |
|
|
125
|
+
| `GET` | `/mlb/statcast-catcher-blocking` | `mlb-statcast-catcher-blocking` | Get Baseball Savant Catcher Blocking leaderboard rows |
|
|
126
|
+
| `GET` | `/mlb/statcast-catcher-blocking-details` | `mlb-statcast-catcher-blocking-details` | Get Baseball Savant Catcher Blocking play details |
|
|
127
|
+
| `GET` | `/mlb/statcast-catcher-framing` | `mlb-statcast-catcher-framing` | Get Baseball Savant Catcher Framing leaderboard rows |
|
|
128
|
+
| `GET` | `/mlb/statcast-catcher-framing-details` | `mlb-statcast-catcher-framing-details` | Get Baseball Savant Catcher Framing pitch-event details |
|
|
129
|
+
| `GET` | `/mlb/statcast-catcher-pop-time` | `mlb-statcast-catcher-pop-time` | Get Baseball Savant Catcher Pop Time leaderboard |
|
|
130
|
+
| `GET` | `/mlb/statcast-catcher-stance` | `mlb-statcast-catcher-stance` | Get Baseball Savant Catcher Stance rows |
|
|
131
|
+
| `GET` | `/mlb/statcast-catcher-throwing` | `mlb-statcast-catcher-throwing` | Get Baseball Savant Catcher Throwing leaderboard rows |
|
|
132
|
+
| `GET` | `/mlb/statcast-catcher-throwing-details` | `mlb-statcast-catcher-throwing-details` | Get Catcher Throwing attempt details |
|
|
133
|
+
| `GET` | `/mlb/statcast-expected` | `mlb-statcast-expected` | Get Baseball Savant Expected Statistics |
|
|
134
|
+
| `GET` | `/mlb/statcast-fielding-run-value` | `mlb-statcast-fielding-run-value` | Get Baseball Savant Fielding Run Value rows |
|
|
135
|
+
| `GET` | `/mlb/statcast-first-base-receiving` | `mlb-statcast-first-base-receiving` | Get Baseball Savant First Base Receiving leaderboards |
|
|
136
|
+
| `GET` | `/mlb/statcast-first-base-receiving-details` | `mlb-statcast-first-base-receiving-details` | Get a player's First Base Receiving play records |
|
|
137
|
+
| `GET` | `/mlb/statcast-home-runs` | `mlb-statcast-home-runs` | Get Baseball Savant Home Runs Tracking |
|
|
138
|
+
| `GET` | `/mlb/statcast-home-runs-details` | `mlb-statcast-home-runs-details` | Get Baseball Savant Home Runs play details |
|
|
139
|
+
| `GET` | `/mlb/statcast-leaders` | `mlb-statcast` | Get Baseball Savant Statcast leaderboard data |
|
|
140
|
+
| `GET` | `/mlb/statcast-oaa` | `mlb-statcast-oaa` | Get Baseball Savant Outs Above Average |
|
|
141
|
+
| `GET` | `/mlb/statcast-park-factors` | `mlb-statcast-park-factors` | Get Baseball Savant Statcast Park Factors rows |
|
|
142
|
+
| `GET` | `/mlb/statcast-percentile` | `mlb-statcast-percentile` | Get Baseball Savant Percentile Rankings |
|
|
143
|
+
| `GET` | `/mlb/statcast-pitch-arsenal` | `mlb-statcast-pitch-arsenal` | Get Baseball Savant Pitch Arsenal Stats |
|
|
144
|
+
| `GET` | `/mlb/statcast-pitch-arsenal-details` | `mlb-statcast-pitch-arsenal-details` | Get Baseball Savant Pitch Arsenal play details |
|
|
145
|
+
| `GET` | `/mlb/statcast-pitch-arsenals` | `mlb-statcast-pitch-arsenals` | Get Baseball Savant Pitch Arsenals |
|
|
146
|
+
| `GET` | `/mlb/statcast-pitch-movement` | `mlb-statcast-pitch-movement` | Get Baseball Savant Pitch Movement rows |
|
|
147
|
+
| `GET` | `/mlb/statcast-pitch-tempo` | `mlb-statcast-pitch-tempo` | Get Baseball Savant Pitch Tempo rows |
|
|
148
|
+
| `GET` | `/mlb/statcast-pitch-tempo-player` | `mlb-statcast-pitch-tempo-player` | Get a player's Pitch Tempo detail rows |
|
|
149
|
+
| `GET` | `/mlb/statcast-pitch-timer` | `mlb-statcast-pitch-timer` | Get Baseball Savant Pitch Timer infraction rows |
|
|
150
|
+
| `GET` | `/mlb/statcast-player-details` | `mlb-statcast-player-details` | Get expanded standard Baseball Savant Statcast player plays |
|
|
151
|
+
| `GET` | `/mlb/statcast-rolling` | `mlb-statcast-rolling` | Get Baseball Savant Rolling Windows rows |
|
|
152
|
+
| `GET` | `/mlb/statcast-run-value` | `mlb-statcast-run-value` | Get Baseball Savant Run Value rows |
|
|
153
|
+
| `GET` | `/mlb/statcast-running-game` | `mlb-statcast-running-game` | Get Baseball Savant Running Game leaderboards |
|
|
154
|
+
| `GET` | `/mlb/statcast-running-game-details` | `mlb-statcast-running-game-details` | Get Baseball Savant Running Game play details |
|
|
155
|
+
| `GET` | `/mlb/statcast-sprint-speed` | `mlb-statcast-sprint-speed` | Get Baseball Savant Sprint Speed player rows |
|
|
156
|
+
| `GET` | `/mlb/statcast-sprint-speed-teams` | `mlb-statcast-sprint-speed-teams` | Get Baseball Savant Sprint Speed team rows |
|
|
157
|
+
| `GET` | `/mlb/statcast-swing-path` | `mlb-statcast-swing-path` | Get Baseball Savant Swing Path and Attack Angle rows |
|
|
158
|
+
| `GET` | `/mlb/statcast-swing-timing` | `mlb-statcast-swing-timing` | Get Baseball Savant Swing Timing and Miss Distance rows |
|
|
159
|
+
| `GET` | `/mlb/statcast-swing-timing-details` | `mlb-statcast-swing-timing-details` | Get Baseball Savant Swing Timing player details |
|
|
160
|
+
| `GET` | `/mlb/statcast-top-performers` | `mlb-statcast-top-performers` | Get Baseball Savant Top Performers |
|
|
161
|
+
| `GET` | `/mlb/statcast-year-to-year` | `mlb-statcast-year-to-year` | Get Baseball Savant Year-to-Year Changes |
|
|
162
|
+
| `GET` | `/mlb/team-roster` | `mlb-team-roster` | Get an MLB team roster |
|
|
163
|
+
| `GET` | `/mlb/team-stats` | `mlb-team-stats` | Get MLB team season statistics |
|
|
164
|
+
| `GET` | `/mlb/teams` | `mlb-teams` | List MLB teams |
|
|
165
|
+
| `GET` | `/mlb/transactions` | `mlb-transactions` | List MLB transactions |
|
|
166
|
+
|
|
167
|
+
## Configuration
|
|
168
|
+
|
|
169
|
+
Pass your key through `api_key` or read `CRAWLORA_API_KEY` from the environment.
|
|
170
|
+
Keep credentials out of source control and logs. Requests go to Crawlora's
|
|
171
|
+
hosted API.
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# crawlora-mlb — MLB API client for Python
|
|
2
|
+
|
|
3
|
+
Python client for Crawlora's hosted MLB API. It exposes 66 API endpoints covering game schedules and details, box scores, standings, player and team statistics, news, and league discovery. Requests go to [Crawlora](https://crawlora.net/?utm_source=pypi&utm_medium=referral&utm_campaign=platform-clients&utm_content=mlb-python-homepage); the package does not run a browser or scrape
|
|
4
|
+
MLB 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
|
+
MLB or its owners.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
python -m pip install crawlora-mlb
|
|
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=mlb-python-signup), then open the [Crawlora console](https://crawlora.net/app?utm_source=pypi&utm_medium=referral&utm_campaign=platform-clients&utm_content=mlb-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_mlb import MLBClient
|
|
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 MLBClient(api_key=api_key) as client:
|
|
36
|
+
result_1 = client.discovery()
|
|
37
|
+
print(result_1)
|
|
38
|
+
result_2 = client.editorial_feed(slug='mlb')
|
|
39
|
+
print(result_2)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The package also exports `Client` as an alias for `MLBClient`. Operation
|
|
43
|
+
methods are available directly in snake_case and through the `mlb`
|
|
44
|
+
group. The async package client is `AsyncMLBClient`; see the [online
|
|
45
|
+
endpoint and parameter reference](https://github.com/Crawlora-org/crawlora-mlb/blob/main/docs/usage.md) and [runnable example](https://github.com/Crawlora-org/crawlora-mlb/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_mlb 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.discovery()
|
|
63
|
+
print(result_1)
|
|
64
|
+
|
|
65
|
+
asyncio.run(main())
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
See the [runnable example](https://github.com/Crawlora-org/crawlora-mlb/blob/main/examples/python.py) for a complete usage example.
|
|
69
|
+
|
|
70
|
+
## Supported MLB API endpoints
|
|
71
|
+
|
|
72
|
+
This package exposes every route below through direct snake_case methods and the `mlb` group. See the [endpoint and parameter reference](https://github.com/Crawlora-org/crawlora-mlb/blob/main/docs/usage.md) for complete input details.
|
|
73
|
+
|
|
74
|
+
| Method | Endpoint | API operation | Description |
|
|
75
|
+
| --- | --- | --- | --- |
|
|
76
|
+
| `GET` | `/mlb/discovery` | `mlb-discovery` | Discover MLB sections and Stats API values |
|
|
77
|
+
| `GET` | `/mlb/editorial-feed` | `mlb-editorial-feed` | Get an MLB.com editorial feed |
|
|
78
|
+
| `GET` | `/mlb/game` | `mlb-game` | Get an MLB game feed |
|
|
79
|
+
| `GET` | `/mlb/game-boxscore` | `mlb-game-boxscore` | Get an MLB player boxscore |
|
|
80
|
+
| `GET` | `/mlb/game-play-by-play` | `mlb-game-play-by-play` | Get MLB game play-by-play |
|
|
81
|
+
| `GET` | `/mlb/league-leaders` | `mlb-league-leaders` | Get MLB league leaders |
|
|
82
|
+
| `GET` | `/mlb/league-stats` | `mlb-league-stats` | Get ranked MLB league statistics |
|
|
83
|
+
| `GET` | `/mlb/player` | `mlb-player` | Get an MLB player |
|
|
84
|
+
| `GET` | `/mlb/player-stats` | `mlb-player-stats` | Get MLB player season statistics |
|
|
85
|
+
| `GET` | `/mlb/prospect-rankings` | `mlb-prospect-rankings` | Get MLB Pipeline curated prospect rankings |
|
|
86
|
+
| `GET` | `/mlb/prospect-stats` | `mlb-prospect-stats` | Get MLB Pipeline prospect statistics and rankings |
|
|
87
|
+
| `GET` | `/mlb/schedule` | `mlb-schedule` | Get the MLB schedule and scores |
|
|
88
|
+
| `GET` | `/mlb/search` | `mlb-search` | Search MLB players, teams, and content topics |
|
|
89
|
+
| `GET` | `/mlb/standings` | `mlb-standings` | Get MLB standings |
|
|
90
|
+
| `GET` | `/mlb/statcast-abs-challenges` | `mlb-statcast-abs-challenges` | Get Baseball Savant ABS challenge rankings |
|
|
91
|
+
| `GET` | `/mlb/statcast-active-spin` | `mlb-statcast-active-spin` | Get Baseball Savant Active Spin rows |
|
|
92
|
+
| `GET` | `/mlb/statcast-arm-angle` | `mlb-statcast-arm-angle` | Get Baseball Savant Pitcher Arm Angle rows |
|
|
93
|
+
| `GET` | `/mlb/statcast-arm-strength` | `mlb-statcast-arm-strength` | Get Baseball Savant Arm Strength leaderboard data |
|
|
94
|
+
| `GET` | `/mlb/statcast-arm-strength-player` | `mlb-statcast-arm-strength-player` | Get Baseball Savant player throw details |
|
|
95
|
+
| `GET` | `/mlb/statcast-arm-value` | `mlb-statcast-arm-value` | Get Baseball Savant Extra Bases Run Value leaderboard data |
|
|
96
|
+
| `GET` | `/mlb/statcast-arm-value-details` | `mlb-statcast-arm-value-details` | Get expanded Baseball Savant Arm Value player plays |
|
|
97
|
+
| `GET` | `/mlb/statcast-baserunning` | `mlb-statcast-baserunning` | Get Baseball Savant baserunning leaderboard tables |
|
|
98
|
+
| `GET` | `/mlb/statcast-bat-tracking` | `mlb-statcast-bat-tracking` | Get Baseball Savant bat-tracking rows |
|
|
99
|
+
| `GET` | `/mlb/statcast-batted-ball` | `mlb-statcast-batted-ball` | Get Baseball Savant Batted Ball Profile rows |
|
|
100
|
+
| `GET` | `/mlb/statcast-birthday-index` | `mlb-statcast-birthday-index` | Get Baseball Savant Sarah Langs Birthday Index rows |
|
|
101
|
+
| `GET` | `/mlb/statcast-catcher-blocking` | `mlb-statcast-catcher-blocking` | Get Baseball Savant Catcher Blocking leaderboard rows |
|
|
102
|
+
| `GET` | `/mlb/statcast-catcher-blocking-details` | `mlb-statcast-catcher-blocking-details` | Get Baseball Savant Catcher Blocking play details |
|
|
103
|
+
| `GET` | `/mlb/statcast-catcher-framing` | `mlb-statcast-catcher-framing` | Get Baseball Savant Catcher Framing leaderboard rows |
|
|
104
|
+
| `GET` | `/mlb/statcast-catcher-framing-details` | `mlb-statcast-catcher-framing-details` | Get Baseball Savant Catcher Framing pitch-event details |
|
|
105
|
+
| `GET` | `/mlb/statcast-catcher-pop-time` | `mlb-statcast-catcher-pop-time` | Get Baseball Savant Catcher Pop Time leaderboard |
|
|
106
|
+
| `GET` | `/mlb/statcast-catcher-stance` | `mlb-statcast-catcher-stance` | Get Baseball Savant Catcher Stance rows |
|
|
107
|
+
| `GET` | `/mlb/statcast-catcher-throwing` | `mlb-statcast-catcher-throwing` | Get Baseball Savant Catcher Throwing leaderboard rows |
|
|
108
|
+
| `GET` | `/mlb/statcast-catcher-throwing-details` | `mlb-statcast-catcher-throwing-details` | Get Catcher Throwing attempt details |
|
|
109
|
+
| `GET` | `/mlb/statcast-expected` | `mlb-statcast-expected` | Get Baseball Savant Expected Statistics |
|
|
110
|
+
| `GET` | `/mlb/statcast-fielding-run-value` | `mlb-statcast-fielding-run-value` | Get Baseball Savant Fielding Run Value rows |
|
|
111
|
+
| `GET` | `/mlb/statcast-first-base-receiving` | `mlb-statcast-first-base-receiving` | Get Baseball Savant First Base Receiving leaderboards |
|
|
112
|
+
| `GET` | `/mlb/statcast-first-base-receiving-details` | `mlb-statcast-first-base-receiving-details` | Get a player's First Base Receiving play records |
|
|
113
|
+
| `GET` | `/mlb/statcast-home-runs` | `mlb-statcast-home-runs` | Get Baseball Savant Home Runs Tracking |
|
|
114
|
+
| `GET` | `/mlb/statcast-home-runs-details` | `mlb-statcast-home-runs-details` | Get Baseball Savant Home Runs play details |
|
|
115
|
+
| `GET` | `/mlb/statcast-leaders` | `mlb-statcast` | Get Baseball Savant Statcast leaderboard data |
|
|
116
|
+
| `GET` | `/mlb/statcast-oaa` | `mlb-statcast-oaa` | Get Baseball Savant Outs Above Average |
|
|
117
|
+
| `GET` | `/mlb/statcast-park-factors` | `mlb-statcast-park-factors` | Get Baseball Savant Statcast Park Factors rows |
|
|
118
|
+
| `GET` | `/mlb/statcast-percentile` | `mlb-statcast-percentile` | Get Baseball Savant Percentile Rankings |
|
|
119
|
+
| `GET` | `/mlb/statcast-pitch-arsenal` | `mlb-statcast-pitch-arsenal` | Get Baseball Savant Pitch Arsenal Stats |
|
|
120
|
+
| `GET` | `/mlb/statcast-pitch-arsenal-details` | `mlb-statcast-pitch-arsenal-details` | Get Baseball Savant Pitch Arsenal play details |
|
|
121
|
+
| `GET` | `/mlb/statcast-pitch-arsenals` | `mlb-statcast-pitch-arsenals` | Get Baseball Savant Pitch Arsenals |
|
|
122
|
+
| `GET` | `/mlb/statcast-pitch-movement` | `mlb-statcast-pitch-movement` | Get Baseball Savant Pitch Movement rows |
|
|
123
|
+
| `GET` | `/mlb/statcast-pitch-tempo` | `mlb-statcast-pitch-tempo` | Get Baseball Savant Pitch Tempo rows |
|
|
124
|
+
| `GET` | `/mlb/statcast-pitch-tempo-player` | `mlb-statcast-pitch-tempo-player` | Get a player's Pitch Tempo detail rows |
|
|
125
|
+
| `GET` | `/mlb/statcast-pitch-timer` | `mlb-statcast-pitch-timer` | Get Baseball Savant Pitch Timer infraction rows |
|
|
126
|
+
| `GET` | `/mlb/statcast-player-details` | `mlb-statcast-player-details` | Get expanded standard Baseball Savant Statcast player plays |
|
|
127
|
+
| `GET` | `/mlb/statcast-rolling` | `mlb-statcast-rolling` | Get Baseball Savant Rolling Windows rows |
|
|
128
|
+
| `GET` | `/mlb/statcast-run-value` | `mlb-statcast-run-value` | Get Baseball Savant Run Value rows |
|
|
129
|
+
| `GET` | `/mlb/statcast-running-game` | `mlb-statcast-running-game` | Get Baseball Savant Running Game leaderboards |
|
|
130
|
+
| `GET` | `/mlb/statcast-running-game-details` | `mlb-statcast-running-game-details` | Get Baseball Savant Running Game play details |
|
|
131
|
+
| `GET` | `/mlb/statcast-sprint-speed` | `mlb-statcast-sprint-speed` | Get Baseball Savant Sprint Speed player rows |
|
|
132
|
+
| `GET` | `/mlb/statcast-sprint-speed-teams` | `mlb-statcast-sprint-speed-teams` | Get Baseball Savant Sprint Speed team rows |
|
|
133
|
+
| `GET` | `/mlb/statcast-swing-path` | `mlb-statcast-swing-path` | Get Baseball Savant Swing Path and Attack Angle rows |
|
|
134
|
+
| `GET` | `/mlb/statcast-swing-timing` | `mlb-statcast-swing-timing` | Get Baseball Savant Swing Timing and Miss Distance rows |
|
|
135
|
+
| `GET` | `/mlb/statcast-swing-timing-details` | `mlb-statcast-swing-timing-details` | Get Baseball Savant Swing Timing player details |
|
|
136
|
+
| `GET` | `/mlb/statcast-top-performers` | `mlb-statcast-top-performers` | Get Baseball Savant Top Performers |
|
|
137
|
+
| `GET` | `/mlb/statcast-year-to-year` | `mlb-statcast-year-to-year` | Get Baseball Savant Year-to-Year Changes |
|
|
138
|
+
| `GET` | `/mlb/team-roster` | `mlb-team-roster` | Get an MLB team roster |
|
|
139
|
+
| `GET` | `/mlb/team-stats` | `mlb-team-stats` | Get MLB team season statistics |
|
|
140
|
+
| `GET` | `/mlb/teams` | `mlb-teams` | List MLB teams |
|
|
141
|
+
| `GET` | `/mlb/transactions` | `mlb-transactions` | List MLB transactions |
|
|
142
|
+
|
|
143
|
+
## Configuration
|
|
144
|
+
|
|
145
|
+
Pass your key through `api_key` or read `CRAWLORA_API_KEY` from the environment.
|
|
146
|
+
Keep credentials out of source control and logs. Requests go to Crawlora's
|
|
147
|
+
hosted API.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Typed MLB client for the Crawlora hosted API."""
|
|
2
|
+
|
|
3
|
+
from .platform import MLBClient, AsyncMLBClient
|
|
4
|
+
from .client import CrawloraClientError, CrawloraError, CrawloraNetworkError, CrawloraServerError
|
|
5
|
+
from .operations import OPERATION_COUNT, OPERATION_IDS, PLATFORM
|
|
6
|
+
|
|
7
|
+
Client = MLBClient
|
|
8
|
+
AsyncClient = AsyncMLBClient
|
|
9
|
+
__version__ = '0.1.0'
|
|
10
|
+
DISPLAY_NAME = 'MLB'
|
|
11
|
+
PLATFORM = 'mlb'
|
|
12
|
+
CONTRACT_REVISION = 'sha256:116cfa4b90f943dd7fbb17babe0207a96736f523debd05025905cc79155cbc0f'
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"MLBClient", "AsyncMLBClient", "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 MLBClient as MLBClient
|
|
2
|
+
from .platform import AsyncMLBClient as AsyncMLBClient
|
|
3
|
+
Client = MLBClient
|
|
4
|
+
AsyncClient = AsyncMLBClient
|
|
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__ = ['MLBClient', 'AsyncMLBClient', '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
|