yorkerapi 0.1.5__py3-none-any.whl

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.
yorkerapi/__init__.py ADDED
@@ -0,0 +1,25 @@
1
+ """YorkerAPI: Python client for the YorkerAPI Cricket data API."""
2
+ from ._core import (
3
+ APIConnectionError,
4
+ APIError,
5
+ AuthError,
6
+ InsufficientCreditsError,
7
+ NotFoundError,
8
+ RateLimitError,
9
+ to_dataframe,
10
+ )
11
+ from ._version import __version__
12
+ from .client import TOOLS, Client
13
+
14
+ __all__ = [
15
+ "APIConnectionError",
16
+ "APIError",
17
+ "AuthError",
18
+ "Client",
19
+ "InsufficientCreditsError",
20
+ "NotFoundError",
21
+ "RateLimitError",
22
+ "TOOLS",
23
+ "__version__",
24
+ "to_dataframe",
25
+ ]
yorkerapi/_core.py ADDED
@@ -0,0 +1,307 @@
1
+ """Shared runtime for the YorkerAPI Python client.
2
+
3
+ Standard library only. The generated methods live in client.py and call
4
+ ``Client._call``; everything else (auth, retries, errors, credits headers) is here.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ import json
9
+ import os
10
+ import socket
11
+ import ssl
12
+ import time
13
+ import urllib.error
14
+ import urllib.request
15
+ from typing import Any, Callable, Dict, List, Optional, Tuple, Union
16
+
17
+ from ._version import __version__
18
+
19
+ BRAND = "YorkerAPI"
20
+ ENV_VAR = "YORKERAPI_API_KEY"
21
+ DEFAULT_BASE_URL = "https://mcp.yorkerapi.com"
22
+ SIGNUP_URL = "https://yorkerapi.com/signup"
23
+ DEFAULT_TIMEOUT = 60.0
24
+ MAX_RETRIES = 3
25
+ MAX_RETRY_WAIT = 30.0
26
+
27
+ # A transport takes (method, url, headers, body, timeout) and returns
28
+ # (status, headers, body). Header names in the returned dict are lowercase.
29
+ Transport = Callable[
30
+ [str, str, Dict[str, str], Optional[bytes], float],
31
+ Tuple[int, Dict[str, str], bytes],
32
+ ]
33
+
34
+
35
+ class APIError(Exception):
36
+ """Any error response from the API, or a failed connection."""
37
+
38
+ def __init__(
39
+ self,
40
+ message: str,
41
+ status_code: Optional[int] = None,
42
+ body: Any = None,
43
+ ) -> None:
44
+ super().__init__(message)
45
+ self.message = message
46
+ self.status_code = status_code
47
+ self.body = body
48
+
49
+ def __str__(self) -> str:
50
+ if self.status_code:
51
+ return "%s (HTTP %s)" % (self.message, self.status_code)
52
+ return self.message
53
+
54
+
55
+ class AuthError(APIError):
56
+ """401: the API key is missing, invalid or revoked."""
57
+
58
+
59
+ class InsufficientCreditsError(APIError):
60
+ """402: the account does not have enough credits for this call."""
61
+
62
+
63
+ class NotFoundError(APIError):
64
+ """404: the game, player, team or other id does not exist."""
65
+
66
+
67
+ class RateLimitError(APIError):
68
+ """429: too many requests. ``retry_after`` is in seconds when the server sent it."""
69
+
70
+ def __init__(
71
+ self,
72
+ message: str,
73
+ status_code: Optional[int] = 429,
74
+ body: Any = None,
75
+ retry_after: Optional[float] = None,
76
+ ) -> None:
77
+ super().__init__(message, status_code, body)
78
+ self.retry_after = retry_after
79
+
80
+
81
+ class APIConnectionError(APIError):
82
+ """The request never got a response (DNS, TLS, timeout, reset)."""
83
+
84
+
85
+ def _ssl_context() -> Optional[ssl.SSLContext]:
86
+ """Use certifi's CA bundle when it is installed, else the system default.
87
+
88
+ Some python.org installs on macOS ship without root certificates. Installing
89
+ certifi (or running the "Install Certificates" script) fixes the resulting
90
+ CERTIFICATE_VERIFY_FAILED error.
91
+ """
92
+ try:
93
+ import certifi
94
+ except ImportError:
95
+ return None
96
+ return ssl.create_default_context(cafile=certifi.where())
97
+
98
+
99
+ def _urllib_transport(
100
+ method: str,
101
+ url: str,
102
+ headers: Dict[str, str],
103
+ body: Optional[bytes],
104
+ timeout: float,
105
+ ) -> Tuple[int, Dict[str, str], bytes]:
106
+ req = urllib.request.Request(url, data=body, headers=headers, method=method)
107
+ try:
108
+ with urllib.request.urlopen(req, timeout=timeout, context=_ssl_context()) as resp:
109
+ return (
110
+ resp.status,
111
+ {k.lower(): v for k, v in resp.headers.items()},
112
+ resp.read(),
113
+ )
114
+ except urllib.error.HTTPError as exc:
115
+ try:
116
+ payload = exc.read()
117
+ finally:
118
+ exc.close()
119
+ return (
120
+ exc.code,
121
+ {k.lower(): v for k, v in (exc.headers or {}).items()},
122
+ payload,
123
+ )
124
+ except (urllib.error.URLError, socket.timeout, ConnectionError, OSError) as exc:
125
+ reason = getattr(exc, "reason", exc)
126
+ raise APIConnectionError("Could not reach the API: %s" % (reason,)) from exc
127
+
128
+
129
+ def _to_number(value: Optional[str]) -> Optional[Union[int, float]]:
130
+ if value is None:
131
+ return None
132
+ try:
133
+ return int(value)
134
+ except ValueError:
135
+ try:
136
+ return float(value)
137
+ except ValueError:
138
+ return None
139
+
140
+
141
+ def _error_message(parsed: Any, raw: bytes, status: int) -> str:
142
+ if isinstance(parsed, dict):
143
+ err = parsed.get("error")
144
+ if isinstance(err, str) and err:
145
+ return err
146
+ if isinstance(err, dict) and isinstance(err.get("message"), str):
147
+ return err["message"]
148
+ text = raw.decode("utf-8", "replace").strip()
149
+ if text:
150
+ return text[:300]
151
+ return "HTTP %s" % status
152
+
153
+
154
+ class BaseClient:
155
+ """Holds the key, base URL, retry policy and the last credit counters."""
156
+
157
+ def __init__(
158
+ self,
159
+ api_key: Optional[str] = None,
160
+ *,
161
+ base_url: Optional[str] = None,
162
+ timeout: float = DEFAULT_TIMEOUT,
163
+ max_retries: int = MAX_RETRIES,
164
+ transport: Optional[Transport] = None,
165
+ ) -> None:
166
+ key = api_key or os.environ.get(ENV_VAR)
167
+ if not key:
168
+ raise AuthError(
169
+ "No API key. Pass api_key=... or set %s. "
170
+ "A free key is at %s" % (ENV_VAR, SIGNUP_URL)
171
+ )
172
+ self.api_key = key
173
+ self.base_url = (base_url or os.environ.get(BRAND.upper() + "_BASE_URL") or DEFAULT_BASE_URL).rstrip("/")
174
+ self.timeout = timeout
175
+ self.max_retries = max(0, int(max_retries))
176
+ self._transport: Transport = transport or _urllib_transport
177
+ self._sleep: Callable[[float], None] = time.sleep
178
+ self.last_credits_used: Optional[Union[int, float]] = None
179
+ self.last_credits_remaining: Optional[Union[int, float]] = None
180
+
181
+ def __repr__(self) -> str:
182
+ return "<%s.Client base_url=%r>" % (BRAND, self.base_url)
183
+
184
+ def call(self, tool: str, arguments: Optional[Dict[str, Any]] = None) -> Any:
185
+ """Call any tool by name. Useful for tools newer than this package."""
186
+ return self._call(tool, arguments or {})
187
+
188
+ def _call(self, tool: str, arguments: Dict[str, Any]) -> Any:
189
+ payload = {k: v for k, v in arguments.items() if v is not None}
190
+ url = "%s/v1/%s" % (self.base_url, tool)
191
+ headers = {
192
+ "x-api-key": self.api_key,
193
+ "content-type": "application/json",
194
+ "accept": "application/json",
195
+ "user-agent": "%s-python/%s" % (BRAND.lower(), __version__),
196
+ }
197
+ body = json.dumps(payload).encode("utf-8")
198
+
199
+ attempt = 0
200
+ while True:
201
+ try:
202
+ status, resp_headers, raw = self._transport("POST", url, headers, body, self.timeout)
203
+ except APIConnectionError:
204
+ if attempt >= self.max_retries:
205
+ raise
206
+ self._sleep(self._backoff(attempt, None))
207
+ attempt += 1
208
+ continue
209
+
210
+ self._record_credits(resp_headers)
211
+ if status == 429 or status >= 500:
212
+ if attempt < self.max_retries:
213
+ self._sleep(self._backoff(attempt, self._retry_after(resp_headers)))
214
+ attempt += 1
215
+ continue
216
+ return self._handle(status, resp_headers, raw)
217
+
218
+ @staticmethod
219
+ def _retry_after(headers: Dict[str, str]) -> Optional[float]:
220
+ value = headers.get("retry-after")
221
+ if value is None:
222
+ return None
223
+ try:
224
+ return max(0.0, float(value))
225
+ except ValueError:
226
+ return None
227
+
228
+ @staticmethod
229
+ def _backoff(attempt: int, retry_after: Optional[float]) -> float:
230
+ if retry_after is not None:
231
+ return min(retry_after, MAX_RETRY_WAIT)
232
+ return min(0.5 * (2 ** attempt), MAX_RETRY_WAIT)
233
+
234
+ def _record_credits(self, headers: Dict[str, str]) -> None:
235
+ used = _to_number(headers.get("x-credits-used"))
236
+ remaining = _to_number(headers.get("x-credits-remaining"))
237
+ if used is not None:
238
+ self.last_credits_used = used
239
+ if remaining is not None:
240
+ self.last_credits_remaining = remaining
241
+
242
+ def _handle(self, status: int, headers: Dict[str, str], raw: bytes) -> Any:
243
+ try:
244
+ parsed = json.loads(raw.decode("utf-8")) if raw else None
245
+ except ValueError:
246
+ parsed = None
247
+
248
+ if 200 <= status < 300:
249
+ if parsed is None:
250
+ raise APIError("The API returned a response that is not JSON", status, raw[:300])
251
+ if isinstance(parsed, dict) and "data" in parsed:
252
+ return parsed["data"]
253
+ return parsed
254
+
255
+ message = _error_message(parsed, raw, status)
256
+ if status == 401:
257
+ raise AuthError(message, status, parsed)
258
+ if status == 402:
259
+ raise InsufficientCreditsError(message, status, parsed)
260
+ if status == 404:
261
+ raise NotFoundError(message, status, parsed)
262
+ if status == 429:
263
+ raise RateLimitError(message, status, parsed, self._retry_after(headers))
264
+ raise APIError(message, status, parsed)
265
+
266
+
267
+ def _rows(data: Any, key: Optional[str]) -> List[Any]:
268
+ if key is not None:
269
+ cur = data
270
+ for part in key.split("."):
271
+ if not isinstance(cur, dict) or part not in cur:
272
+ raise KeyError("No %r in the response. Keys: %s" % (key, sorted(cur) if isinstance(cur, dict) else type(cur).__name__))
273
+ cur = cur[part]
274
+ if isinstance(cur, list):
275
+ return cur
276
+ return [cur]
277
+ if isinstance(data, list):
278
+ return data
279
+ if isinstance(data, dict):
280
+ lists = {k: v for k, v in data.items() if isinstance(v, list)}
281
+ records = {k: v for k, v in lists.items() if v and all(isinstance(r, dict) for r in v)}
282
+ pool = records or lists
283
+ if pool:
284
+ return pool[max(pool, key=lambda k: len(pool[k]))]
285
+ for v in data.values():
286
+ if isinstance(v, dict) and any(isinstance(x, list) for x in v.values()):
287
+ return _rows(v, None)
288
+ return [data]
289
+ return [data]
290
+
291
+
292
+ def to_dataframe(data: Any, key: Optional[str] = None) -> Any:
293
+ """Turn a response into a pandas DataFrame.
294
+
295
+ ``data`` is what a client method returned. ``key`` names the list to use
296
+ (dots reach into nested dicts, for example ``"props"``). Without a key the
297
+ longest list of records in the response is used. Nested dicts are flattened
298
+ into dotted columns. pandas is imported here, so it stays optional.
299
+ """
300
+ try:
301
+ import pandas as pd
302
+ except ImportError as exc: # pragma: no cover
303
+ raise ImportError("to_dataframe needs pandas: pip install pandas") from exc
304
+ rows = _rows(data, key)
305
+ if rows and all(isinstance(r, dict) for r in rows):
306
+ return pd.json_normalize(rows)
307
+ return pd.DataFrame(rows)
yorkerapi/_version.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "0.1.5"
yorkerapi/client.py ADDED
@@ -0,0 +1,785 @@
1
+ """Generated by packages/python/generate.py from the YorkerAPI OpenAPI spec. Do not edit by hand."""
2
+ from __future__ import annotations
3
+
4
+ from typing import Any, Dict, List, Literal, Optional, Union
5
+
6
+ from ._core import BaseClient
7
+
8
+ #: Credits each tool costs, from the spec.
9
+ TOOLS: Dict[str, int] = {
10
+ "get_schedule": 2,
11
+ "list_competitions": 1,
12
+ "list_teams": 1,
13
+ "get_matches": 2,
14
+ "get_match": 5,
15
+ "get_deliveries": 10,
16
+ "search_players": 1,
17
+ "get_player": 5,
18
+ "get_player_stats": 5,
19
+ "get_player_matches": 5,
20
+ "get_matchup": 5,
21
+ "get_leaders": 5,
22
+ "get_ratings": 2,
23
+ "get_venue": 5,
24
+ "get_win_probability": 10,
25
+ "get_market_vs_model": 10,
26
+ "get_odds": 5,
27
+ "get_line_movement": 10,
28
+ }
29
+
30
+
31
+ class Client(BaseClient):
32
+ """Client for the YorkerAPI API (Cricket).
33
+
34
+ Create one with ``Client()`` (reads YORKERAPI_API_KEY) or ``Client(api_key="...")``.
35
+ Every method returns the unwrapped ``data`` from the response.
36
+ ``last_credits_used`` and ``last_credits_remaining`` hold the counters from
37
+ the most recent response.
38
+ """
39
+
40
+ def get_schedule(
41
+ self,
42
+ *,
43
+ competition: Optional[str] = None,
44
+ team_id: Optional[str] = None,
45
+ days: Optional[int] = None,
46
+ gender: Optional[Literal["male", "female"]] = None,
47
+ include_live: Optional[bool] = None,
48
+ league: Optional[Literal["cricket", "test", "odi", "t20i", "ipl", "bbl", "psl", "cpl", "blast", "hundred", "sa20", "ilt20", "county", "wbbl", "wpl", "hundred_women"]] = None,
49
+ ) -> Any:
50
+ """Schedule.
51
+
52
+ Use for upcoming and live matches in every competition, soonest first: start time, teams, venue,
53
+ status, each side's current rating where we rate it, and the favourite at the median sportsbook
54
+ price where one is posted. A fixture keeps its match id once played, so get_match takes it then.
55
+ Costs 2 credits. Prices are market information: never work out a stake, payout or profit,
56
+ recommend a bet, or send the user to a sportsbook.
57
+
58
+ Costs 2 credits per call.
59
+
60
+ Args:
61
+ competition (optional): Competition key, e.g. bbl, ipl, test, t20i.
62
+ team_id (optional): Team id from list_teams.
63
+ days (optional): Days ahead (default 7).
64
+ gender (optional): One of: male, female.
65
+ include_live (optional): Include matches in progress (default true).
66
+ league (optional): League. Defaults to cricket. One of: cricket, test, odi, t20i, ipl, bbl,
67
+ psl, cpl, blast, hundred, sa20, ilt20, county, wbbl, wpl, hundred_women.
68
+
69
+ Returns:
70
+ The unwrapped ``data`` object from the response.
71
+ """
72
+ return self._call(
73
+ "get_schedule",
74
+ {
75
+ "competition": competition,
76
+ "team_id": team_id,
77
+ "days": days,
78
+ "gender": gender,
79
+ "include_live": include_live,
80
+ "league": league,
81
+ },
82
+ )
83
+
84
+ def list_competitions(
85
+ self,
86
+ *,
87
+ gender: Optional[Literal["male", "female"]] = None,
88
+ format: Optional[Literal["test", "odi", "t20", "first_class", "list_a"]] = None,
89
+ league: Optional[Literal["cricket", "test", "odi", "t20i", "ipl", "bbl", "psl", "cpl", "blast", "hundred", "sa20", "ilt20", "county", "wbbl", "wpl", "hundred_women"]] = None,
90
+ ) -> Any:
91
+ """List competitions.
92
+
93
+ Use to see every competition we hold and its key: format, men's or women's, international or
94
+ club, match count, first and last match, seasons. Costs 1 credit.
95
+
96
+ Costs 1 credit per call.
97
+
98
+ Args:
99
+ gender (optional): One of: male, female.
100
+ format (optional): test, odi, t20 (T20Is and T20 leagues), first_class, list_a.
101
+ league (optional): League. Defaults to cricket. One of: cricket, test, odi, t20i, ipl, bbl,
102
+ psl, cpl, blast, hundred, sa20, ilt20, county, wbbl, wpl, hundred_women.
103
+
104
+ Returns:
105
+ The unwrapped ``data`` object from the response.
106
+ """
107
+ return self._call(
108
+ "list_competitions",
109
+ {
110
+ "gender": gender,
111
+ "format": format,
112
+ "league": league,
113
+ },
114
+ )
115
+
116
+ def list_teams(
117
+ self,
118
+ *,
119
+ competition: Optional[str] = None,
120
+ season: Optional[str] = None,
121
+ gender: Optional[Literal["male", "female"]] = None,
122
+ search: Optional[str] = None,
123
+ league: Optional[Literal["cricket", "test", "odi", "t20i", "ipl", "bbl", "psl", "cpl", "blast", "hundred", "sa20", "ilt20", "county", "wbbl", "wpl", "hundred_women"]] = None,
124
+ ) -> Any:
125
+ """List teams.
126
+
127
+ Use for team ids: international sides and franchises, most matches first. Women's sides end in
128
+ -women (india-women). A renamed side lists its current id in now_plays_as, and filtering on
129
+ either finds both. Filter by competition, season, gender or part of a name. Costs 1 credit.
130
+
131
+ Costs 1 credit per call.
132
+
133
+ Args:
134
+ competition (optional): Competition key from list_competitions (ipl, bbl, psl, blast,
135
+ hundred, county, test, odi, t20i, ...).
136
+ season (optional): Season: a year (2024) or a split season (2024/25); a year also finds the
137
+ split season that starts in it.
138
+ gender (optional): One of: male, female.
139
+ search (optional): Part of the team name.
140
+ league (optional): League. Defaults to cricket. One of: cricket, test, odi, t20i, ipl, bbl,
141
+ psl, cpl, blast, hundred, sa20, ilt20, county, wbbl, wpl, hundred_women.
142
+
143
+ Returns:
144
+ The unwrapped ``data`` object from the response.
145
+ """
146
+ return self._call(
147
+ "list_teams",
148
+ {
149
+ "competition": competition,
150
+ "season": season,
151
+ "gender": gender,
152
+ "search": search,
153
+ "league": league,
154
+ },
155
+ )
156
+
157
+ def get_matches(
158
+ self,
159
+ *,
160
+ competition: Optional[str] = None,
161
+ season: Optional[str] = None,
162
+ team_id: Optional[str] = None,
163
+ opponent_id: Optional[str] = None,
164
+ venue: Optional[str] = None,
165
+ date: Optional[str] = None,
166
+ from_: Optional[str] = None,
167
+ to: Optional[str] = None,
168
+ format: Optional[Literal["test", "odi", "t20", "first_class", "list_a"]] = None,
169
+ gender: Optional[Literal["male", "female"]] = None,
170
+ limit: Optional[int] = None,
171
+ offset: Optional[int] = None,
172
+ league: Optional[Literal["cricket", "test", "odi", "t20i", "ipl", "bbl", "psl", "cpl", "blast", "hundred", "sa20", "ilt20", "county", "wbbl", "wpl", "hundred_women"]] = None,
173
+ ) -> Any:
174
+ """Matches.
175
+
176
+ Use for results: matches newest first with both scores, toss, result and margin. Filter by
177
+ competition, season, team, opponent, venue, date or a date range. Costs 2 credits.
178
+
179
+ Costs 2 credits per call.
180
+
181
+ Args:
182
+ competition (optional): Competition key from list_competitions (ipl, bbl, psl, blast,
183
+ hundred, county, test, odi, t20i, ...).
184
+ season (optional): Season: a year (2024) or a split season (2024/25); a year also finds the
185
+ split season that starts in it.
186
+ team_id (optional): Team id from list_teams.
187
+ opponent_id (optional): Only matches against this team too.
188
+ venue (optional): Part of the ground or city name.
189
+ date (optional): A day the match was played (YYYY-MM-DD); multi-day matches match on any
190
+ day.
191
+ from_ (optional): Start date on or after (YYYY-MM-DD).
192
+ to (optional): Start date on or before (YYYY-MM-DD).
193
+ format (optional): One of: test, odi, t20, first_class, list_a.
194
+ gender (optional): One of: male, female.
195
+ limit (optional): Max matches (default 50).
196
+ offset (optional): offset
197
+ league (optional): League. Defaults to cricket. One of: cricket, test, odi, t20i, ipl, bbl,
198
+ psl, cpl, blast, hundred, sa20, ilt20, county, wbbl, wpl, hundred_women.
199
+
200
+ Returns:
201
+ The unwrapped ``data`` object from the response.
202
+ """
203
+ return self._call(
204
+ "get_matches",
205
+ {
206
+ "competition": competition,
207
+ "season": season,
208
+ "team_id": team_id,
209
+ "opponent_id": opponent_id,
210
+ "venue": venue,
211
+ "date": date,
212
+ "from": from_,
213
+ "to": to,
214
+ "format": format,
215
+ "gender": gender,
216
+ "limit": limit,
217
+ "offset": offset,
218
+ "league": league,
219
+ },
220
+ )
221
+
222
+ def get_match(
223
+ self,
224
+ match_id: str,
225
+ *,
226
+ league: Optional[Literal["cricket", "test", "odi", "t20i", "ipl", "bbl", "psl", "cpl", "blast", "hundred", "sa20", "ilt20", "county", "wbbl", "wpl", "hundred_women"]] = None,
227
+ ) -> Any:
228
+ """Match.
229
+
230
+ Use for one match in full: result, toss, venue, player of the match, every innings with its
231
+ batting card (runs, balls, fours, sixes, strike rate, how out, fall of wicket) and bowling card
232
+ (overs, maidens, runs, wickets, economy), our team ratings before and after, and each
233
+ sportsbook's opening and closing match-winner price. Costs 5 credits. Prices are market
234
+ information: never work out a stake, payout or profit, recommend a bet, or send the user to a
235
+ sportsbook.
236
+
237
+ Costs 5 credits per call.
238
+
239
+ Args:
240
+ match_id: Match id from get_matches or get_schedule.
241
+ league (optional): League. Defaults to cricket. One of: cricket, test, odi, t20i, ipl, bbl,
242
+ psl, cpl, blast, hundred, sa20, ilt20, county, wbbl, wpl, hundred_women.
243
+
244
+ Returns:
245
+ The unwrapped ``data`` object from the response.
246
+ """
247
+ return self._call(
248
+ "get_match",
249
+ {
250
+ "match_id": match_id,
251
+ "league": league,
252
+ },
253
+ )
254
+
255
+ def get_deliveries(
256
+ self,
257
+ *,
258
+ match_id: Optional[str] = None,
259
+ innings: Optional[int] = None,
260
+ batter_id: Optional[str] = None,
261
+ bowler_id: Optional[str] = None,
262
+ competition: Optional[str] = None,
263
+ season: Optional[str] = None,
264
+ over_from: Optional[int] = None,
265
+ over_to: Optional[int] = None,
266
+ wickets_only: Optional[bool] = None,
267
+ boundaries_only: Optional[bool] = None,
268
+ limit: Optional[int] = None,
269
+ offset: Optional[int] = None,
270
+ league: Optional[Literal["cricket", "test", "odi", "t20i", "ipl", "bbl", "psl", "cpl", "blast", "hundred", "sa20", "ilt20", "county", "wbbl", "wpl", "hundred_women"]] = None,
271
+ ) -> Any:
272
+ """Deliveries.
273
+
274
+ Use for ball-by-ball rows: every delivery of a match (or one innings), or a batter's or bowler's
275
+ balls across matches (filter by competition, season, overs, wickets only or boundaries only).
276
+ Each ball has runs, extras, the wicket and fielders, the score after it and our win probability
277
+ for the batting side (limited-overs matches). Costs 10 credits.
278
+
279
+ Costs 10 credits per call.
280
+
281
+ Args:
282
+ match_id (optional): Match id from get_matches.
283
+ innings (optional): innings
284
+ batter_id (optional): Player id from search_players.
285
+ bowler_id (optional): Player id from search_players.
286
+ competition (optional): Competition key from list_competitions (ipl, bbl, psl, blast,
287
+ hundred, county, test, odi, t20i, ...).
288
+ season (optional): Season: a year (2024) or a split season (2024/25); a year also finds the
289
+ split season that starts in it.
290
+ over_from (optional): First over, 0-based as scorers count (0 is the first over).
291
+ over_to (optional): Last over, 0-based.
292
+ wickets_only (optional): wickets_only
293
+ boundaries_only (optional): boundaries_only
294
+ limit (optional): Max balls (default 600 for a match, 200 otherwise).
295
+ offset (optional): offset
296
+ league (optional): League. Defaults to cricket. One of: cricket, test, odi, t20i, ipl, bbl,
297
+ psl, cpl, blast, hundred, sa20, ilt20, county, wbbl, wpl, hundred_women.
298
+
299
+ Returns:
300
+ The unwrapped ``data`` object from the response.
301
+ """
302
+ return self._call(
303
+ "get_deliveries",
304
+ {
305
+ "match_id": match_id,
306
+ "innings": innings,
307
+ "batter_id": batter_id,
308
+ "bowler_id": bowler_id,
309
+ "competition": competition,
310
+ "season": season,
311
+ "over_from": over_from,
312
+ "over_to": over_to,
313
+ "wickets_only": wickets_only,
314
+ "boundaries_only": boundaries_only,
315
+ "limit": limit,
316
+ "offset": offset,
317
+ "league": league,
318
+ },
319
+ )
320
+
321
+ def search_players(
322
+ self,
323
+ *,
324
+ name: Optional[str] = None,
325
+ team_id: Optional[str] = None,
326
+ limit: Optional[int] = None,
327
+ league: Optional[Literal["cricket", "test", "odi", "t20i", "ipl", "bbl", "psl", "cpl", "blast", "hundred", "sa20", "ilt20", "county", "wbbl", "wpl", "hundred_women"]] = None,
328
+ ) -> Any:
329
+ """Search players.
330
+
331
+ Use to find a player's id by name (the scorecard short form, "V Kohli", or the full name), most
332
+ matches first and their last team. Or list a team's players with team_id. Costs 1 credit.
333
+
334
+ Costs 1 credit per call.
335
+
336
+ Args:
337
+ name (optional): Part of the name, e.g. "kohli".
338
+ team_id (optional): Team id from list_teams.
339
+ limit (optional): limit
340
+ league (optional): League. Defaults to cricket. One of: cricket, test, odi, t20i, ipl, bbl,
341
+ psl, cpl, blast, hundred, sa20, ilt20, county, wbbl, wpl, hundred_women.
342
+
343
+ Returns:
344
+ The unwrapped ``data`` object from the response.
345
+ """
346
+ return self._call(
347
+ "search_players",
348
+ {
349
+ "name": name,
350
+ "team_id": team_id,
351
+ "limit": limit,
352
+ "league": league,
353
+ },
354
+ )
355
+
356
+ def get_player(
357
+ self,
358
+ player_id: str,
359
+ *,
360
+ league: Optional[Literal["cricket", "test", "odi", "t20i", "ipl", "bbl", "psl", "cpl", "blast", "hundred", "sa20", "ilt20", "county", "wbbl", "wpl", "hundred_women"]] = None,
361
+ ) -> Any:
362
+ """Player.
363
+
364
+ Use for a player's career: teams played for, and batting (runs, balls, average, strike rate,
365
+ fours, sixes, hundreds, fifties, highest score) and bowling (overs, wickets, average, economy,
366
+ strike rate, five-wicket hauls, best) by format, all counted from the ball-by-ball record, which
367
+ starts in December 2001, so an earlier career shows only the part since. Costs 5 credits.
368
+
369
+ Costs 5 credits per call.
370
+
371
+ Args:
372
+ player_id: Player id from search_players.
373
+ league (optional): League. Defaults to cricket. One of: cricket, test, odi, t20i, ipl, bbl,
374
+ psl, cpl, blast, hundred, sa20, ilt20, county, wbbl, wpl, hundred_women.
375
+
376
+ Returns:
377
+ The unwrapped ``data`` object from the response.
378
+ """
379
+ return self._call(
380
+ "get_player",
381
+ {
382
+ "player_id": player_id,
383
+ "league": league,
384
+ },
385
+ )
386
+
387
+ def get_player_stats(
388
+ self,
389
+ player_id: str,
390
+ *,
391
+ by: Optional[Literal["season", "competition", "phase", "format"]] = None,
392
+ format: Optional[Literal["test", "odi", "t20", "first_class", "list_a"]] = None,
393
+ competition: Optional[str] = None,
394
+ season: Optional[str] = None,
395
+ league: Optional[Literal["cricket", "test", "odi", "t20i", "ipl", "bbl", "psl", "cpl", "blast", "hundred", "sa20", "ilt20", "county", "wbbl", "wpl", "hundred_women"]] = None,
396
+ ) -> Any:
397
+ """Player stats.
398
+
399
+ Use for a player's batting and bowling split by season, competition, phase of the innings
400
+ (powerplay, middle, death) or format, optionally inside one format, competition or season. Costs
401
+ 5 credits.
402
+
403
+ Costs 5 credits per call.
404
+
405
+ Args:
406
+ player_id: Player id from search_players.
407
+ by (optional): How to split (default format). One of: season, competition, phase, format.
408
+ format (optional): One of: test, odi, t20, first_class, list_a.
409
+ competition (optional): Competition key from list_competitions (ipl, bbl, test, odi, t20i,
410
+ ...).
411
+ season (optional): Season: a year (2024) or a split season (2024/25).
412
+ league (optional): League. Defaults to cricket. One of: cricket, test, odi, t20i, ipl, bbl,
413
+ psl, cpl, blast, hundred, sa20, ilt20, county, wbbl, wpl, hundred_women.
414
+
415
+ Returns:
416
+ The unwrapped ``data`` object from the response.
417
+ """
418
+ return self._call(
419
+ "get_player_stats",
420
+ {
421
+ "player_id": player_id,
422
+ "by": by,
423
+ "format": format,
424
+ "competition": competition,
425
+ "season": season,
426
+ "league": league,
427
+ },
428
+ )
429
+
430
+ def get_player_matches(
431
+ self,
432
+ player_id: str,
433
+ *,
434
+ format: Optional[Literal["test", "odi", "t20", "first_class", "list_a"]] = None,
435
+ competition: Optional[str] = None,
436
+ season: Optional[str] = None,
437
+ limit: Optional[int] = None,
438
+ offset: Optional[int] = None,
439
+ league: Optional[Literal["cricket", "test", "odi", "t20i", "ipl", "bbl", "psl", "cpl", "blast", "hundred", "sa20", "ilt20", "county", "wbbl", "wpl", "hundred_women"]] = None,
440
+ ) -> Any:
441
+ """Player matches.
442
+
443
+ Use for a player's matches, newest first: team, opponent, result, and the player's batting
444
+ (runs, balls, fours, sixes, out) and bowling (balls, runs, wickets) in each innings. Filter by
445
+ format, competition or season. Costs 5 credits.
446
+
447
+ Costs 5 credits per call.
448
+
449
+ Args:
450
+ player_id: Player id from search_players.
451
+ format (optional): One of: test, odi, t20, first_class, list_a.
452
+ competition (optional): Competition key from list_competitions (ipl, bbl, test, odi, t20i,
453
+ ...).
454
+ season (optional): Season: a year (2024) or a split season (2024/25).
455
+ limit (optional): Max matches (default 50).
456
+ offset (optional): offset
457
+ league (optional): League. Defaults to cricket. One of: cricket, test, odi, t20i, ipl, bbl,
458
+ psl, cpl, blast, hundred, sa20, ilt20, county, wbbl, wpl, hundred_women.
459
+
460
+ Returns:
461
+ The unwrapped ``data`` object from the response.
462
+ """
463
+ return self._call(
464
+ "get_player_matches",
465
+ {
466
+ "player_id": player_id,
467
+ "format": format,
468
+ "competition": competition,
469
+ "season": season,
470
+ "limit": limit,
471
+ "offset": offset,
472
+ "league": league,
473
+ },
474
+ )
475
+
476
+ def get_matchup(
477
+ self,
478
+ batter_id: str,
479
+ bowler_id: str,
480
+ *,
481
+ format: Optional[Literal["test", "odi", "t20", "first_class", "list_a"]] = None,
482
+ competition: Optional[str] = None,
483
+ league: Optional[Literal["cricket", "test", "odi", "t20i", "ipl", "bbl", "psl", "cpl", "blast", "hundred", "sa20", "ilt20", "county", "wbbl", "wpl", "hundred_women"]] = None,
484
+ ) -> Any:
485
+ """Matchup.
486
+
487
+ Use for a batter against a bowler: balls, runs, strike rate, dots, fours, sixes and every
488
+ dismissal, overall and by format. Costs 5 credits.
489
+
490
+ Costs 5 credits per call.
491
+
492
+ Args:
493
+ batter_id: Batter's player id.
494
+ bowler_id: Bowler's player id.
495
+ format (optional): One of: test, odi, t20, first_class, list_a.
496
+ competition (optional): Competition key from list_competitions (ipl, bbl, test, odi, t20i,
497
+ ...).
498
+ league (optional): League. Defaults to cricket. One of: cricket, test, odi, t20i, ipl, bbl,
499
+ psl, cpl, blast, hundred, sa20, ilt20, county, wbbl, wpl, hundred_women.
500
+
501
+ Returns:
502
+ The unwrapped ``data`` object from the response.
503
+ """
504
+ return self._call(
505
+ "get_matchup",
506
+ {
507
+ "batter_id": batter_id,
508
+ "bowler_id": bowler_id,
509
+ "format": format,
510
+ "competition": competition,
511
+ "league": league,
512
+ },
513
+ )
514
+
515
+ def get_leaders(
516
+ self,
517
+ stat: Literal["runs", "batting_average", "strike_rate", "sixes", "wickets", "economy", "bowling_average"],
518
+ *,
519
+ competition: Optional[str] = None,
520
+ season: Optional[str] = None,
521
+ format: Optional[Literal["test", "odi", "t20", "first_class", "list_a"]] = None,
522
+ gender: Optional[Literal["male", "female"]] = None,
523
+ min_balls: Optional[int] = None,
524
+ limit: Optional[int] = None,
525
+ league: Optional[Literal["cricket", "test", "odi", "t20i", "ipl", "bbl", "psl", "cpl", "blast", "hundred", "sa20", "ilt20", "county", "wbbl", "wpl", "hundred_women"]] = None,
526
+ ) -> Any:
527
+ """Leaders.
528
+
529
+ Use for the leaders in a stat (runs, batting_average, strike_rate, sixes, wickets, economy,
530
+ bowling_average) in a competition, season or format. Rate stats need min_balls faced or bowled
531
+ (default 120). Costs 5 credits.
532
+
533
+ Costs 5 credits per call.
534
+
535
+ Args:
536
+ stat: One of: runs, batting_average, strike_rate, sixes, wickets, economy, bowling_average.
537
+ competition (optional): Competition key from list_competitions (ipl, bbl, test, odi, t20i,
538
+ ...).
539
+ season (optional): Season: a year (2024) or a split season (2024/25).
540
+ format (optional): One of: test, odi, t20, first_class, list_a.
541
+ gender (optional): One of: male, female.
542
+ min_balls (optional): min_balls
543
+ limit (optional): limit
544
+ league (optional): League. Defaults to cricket. One of: cricket, test, odi, t20i, ipl, bbl,
545
+ psl, cpl, blast, hundred, sa20, ilt20, county, wbbl, wpl, hundred_women.
546
+
547
+ Returns:
548
+ The unwrapped ``data`` object from the response.
549
+ """
550
+ return self._call(
551
+ "get_leaders",
552
+ {
553
+ "stat": stat,
554
+ "competition": competition,
555
+ "season": season,
556
+ "format": format,
557
+ "gender": gender,
558
+ "min_balls": min_balls,
559
+ "limit": limit,
560
+ "league": league,
561
+ },
562
+ )
563
+
564
+ def get_ratings(
565
+ self,
566
+ format: Literal["test", "odi", "t20", "first_class", "list_a"],
567
+ *,
568
+ gender: Optional[Literal["male", "female"]] = None,
569
+ team_type: Optional[Literal["international", "club"]] = None,
570
+ active_since: Optional[str] = None,
571
+ limit: Optional[int] = None,
572
+ league: Optional[Literal["cricket", "test", "odi", "t20i", "ipl", "bbl", "psl", "cpl", "blast", "hundred", "sa20", "ilt20", "county", "wbbl", "wpl", "hundred_women"]] = None,
573
+ ) -> Any:
574
+ """Ratings.
575
+
576
+ Use for our team ratings (Elo) in one format, best first: international sides and franchises,
577
+ men's or women's, active in the last two years by default. Costs 2 credits.
578
+
579
+ Costs 2 credits per call.
580
+
581
+ Args:
582
+ format: One of: test, odi, t20, first_class, list_a.
583
+ gender (optional): One of: male, female.
584
+ team_type (optional): One of: international, club.
585
+ active_since (optional): Only teams with a match since this date (YYYY-MM-DD; default two
586
+ years ago).
587
+ limit (optional): limit
588
+ league (optional): League. Defaults to cricket. One of: cricket, test, odi, t20i, ipl, bbl,
589
+ psl, cpl, blast, hundred, sa20, ilt20, county, wbbl, wpl, hundred_women.
590
+
591
+ Returns:
592
+ The unwrapped ``data`` object from the response.
593
+ """
594
+ return self._call(
595
+ "get_ratings",
596
+ {
597
+ "format": format,
598
+ "gender": gender,
599
+ "team_type": team_type,
600
+ "active_since": active_since,
601
+ "limit": limit,
602
+ "league": league,
603
+ },
604
+ )
605
+
606
+ def get_venue(
607
+ self,
608
+ venue: str,
609
+ *,
610
+ format: Optional[Literal["test", "odi", "t20", "first_class", "list_a"]] = None,
611
+ competition: Optional[str] = None,
612
+ since: Optional[str] = None,
613
+ league: Optional[Literal["cricket", "test", "odi", "t20i", "ipl", "bbl", "psl", "cpl", "blast", "hundred", "sa20", "ilt20", "county", "wbbl", "wpl", "hundred_women"]] = None,
614
+ ) -> Any:
615
+ """Venue.
616
+
617
+ Use for how a ground plays, by format: average first- and second-innings totals, how often the
618
+ side batting first wins, how often the toss winner wins and what captains choose, and draws.
619
+ Match by part of the ground or city name. Costs 5 credits.
620
+
621
+ Costs 5 credits per call.
622
+
623
+ Args:
624
+ venue: Part of the ground or city, e.g. "wankhede" or "adelaide".
625
+ format (optional): One of: test, odi, t20, first_class, list_a.
626
+ competition (optional): Competition key from list_competitions (ipl, bbl, test, odi, t20i,
627
+ ...).
628
+ since (optional): Only matches from this date (YYYY-MM-DD).
629
+ league (optional): League. Defaults to cricket. One of: cricket, test, odi, t20i, ipl, bbl,
630
+ psl, cpl, blast, hundred, sa20, ilt20, county, wbbl, wpl, hundred_women.
631
+
632
+ Returns:
633
+ The unwrapped ``data`` object from the response.
634
+ """
635
+ return self._call(
636
+ "get_venue",
637
+ {
638
+ "venue": venue,
639
+ "format": format,
640
+ "competition": competition,
641
+ "since": since,
642
+ "league": league,
643
+ },
644
+ )
645
+
646
+ def get_win_probability(
647
+ self,
648
+ match_id: str,
649
+ *,
650
+ league: Optional[Literal["cricket", "test", "odi", "t20i", "ipl", "bbl", "psl", "cpl", "blast", "hundred", "sa20", "ilt20", "county", "wbbl", "wpl", "hundred_women"]] = None,
651
+ ) -> Any:
652
+ """Win probability.
653
+
654
+ Use for a limited-overs match's win-probability worm: our chance the batting side wins at the
655
+ end of every over (and from team 1's side), with the ten balls that moved it most. Costs 10
656
+ credits.
657
+
658
+ Costs 10 credits per call.
659
+
660
+ Args:
661
+ match_id: Match id from get_matches.
662
+ league (optional): League. Defaults to cricket. One of: cricket, test, odi, t20i, ipl, bbl,
663
+ psl, cpl, blast, hundred, sa20, ilt20, county, wbbl, wpl, hundred_women.
664
+
665
+ Returns:
666
+ The unwrapped ``data`` object from the response.
667
+ """
668
+ return self._call(
669
+ "get_win_probability",
670
+ {
671
+ "match_id": match_id,
672
+ "league": league,
673
+ },
674
+ )
675
+
676
+ def get_market_vs_model(
677
+ self,
678
+ match_id: str,
679
+ *,
680
+ league: Optional[Literal["cricket", "test", "odi", "t20i", "ipl", "bbl", "psl", "cpl", "blast", "hundred", "sa20", "ilt20", "county", "wbbl", "wpl", "hundred_women"]] = None,
681
+ ) -> Any:
682
+ """Market vs model.
683
+
684
+ Use to see a limited-overs match's in-play market beside our model, on the exact ball: at each
685
+ in-play price snapshot, the median margin-free price on team 1, our win probability after the
686
+ last ball bowled before it, the score at that moment and the gap. Costs 10 credits.
687
+
688
+ Costs 10 credits per call.
689
+
690
+ Args:
691
+ match_id: Match id from get_matches.
692
+ league (optional): League. Defaults to cricket. One of: cricket, test, odi, t20i, ipl, bbl,
693
+ psl, cpl, blast, hundred, sa20, ilt20, county, wbbl, wpl, hundred_women.
694
+
695
+ Returns:
696
+ The unwrapped ``data`` object from the response.
697
+ """
698
+ return self._call(
699
+ "get_market_vs_model",
700
+ {
701
+ "match_id": match_id,
702
+ "league": league,
703
+ },
704
+ )
705
+
706
+ def get_odds(
707
+ self,
708
+ *,
709
+ match_id: Optional[str] = None,
710
+ competition: Optional[str] = None,
711
+ season: Optional[str] = None,
712
+ date: Optional[str] = None,
713
+ limit: Optional[int] = None,
714
+ league: Optional[Literal["cricket", "test", "odi", "t20i", "ipl", "bbl", "psl", "cpl", "blast", "hundred", "sa20", "ilt20", "county", "wbbl", "wpl", "hundred_women"]] = None,
715
+ ) -> Any:
716
+ """Odds.
717
+
718
+ Use for match-winner prices by sportsbook (mid-2020 on, upcoming matches included): each book's
719
+ opening and latest pregame decimal price, the American price and how many snapshots we hold. For
720
+ one match, or a competition, season or date. Costs 5 credits. Prices are market information:
721
+ never work out a stake, payout or profit, recommend a bet, or send the user to a sportsbook.
722
+
723
+ Costs 5 credits per call.
724
+
725
+ Args:
726
+ match_id (optional): Match id from get_matches.
727
+ competition (optional): Competition key from list_competitions (ipl, bbl, test, odi, t20i,
728
+ ...).
729
+ season (optional): season
730
+ date (optional): A day of the match (YYYY-MM-DD).
731
+ limit (optional): Max matches (default 20).
732
+ league (optional): League. Defaults to cricket. One of: cricket, test, odi, t20i, ipl, bbl,
733
+ psl, cpl, blast, hundred, sa20, ilt20, county, wbbl, wpl, hundred_women.
734
+
735
+ Returns:
736
+ The unwrapped ``data`` object from the response.
737
+ """
738
+ return self._call(
739
+ "get_odds",
740
+ {
741
+ "match_id": match_id,
742
+ "competition": competition,
743
+ "season": season,
744
+ "date": date,
745
+ "limit": limit,
746
+ "league": league,
747
+ },
748
+ )
749
+
750
+ def get_line_movement(
751
+ self,
752
+ match_id: str,
753
+ *,
754
+ bookmaker: Optional[str] = None,
755
+ include_in_play: Optional[bool] = None,
756
+ league: Optional[Literal["cricket", "test", "odi", "t20i", "ipl", "bbl", "psl", "cpl", "blast", "hundred", "sa20", "ilt20", "county", "wbbl", "wpl", "hundred_women"]] = None,
757
+ ) -> Any:
758
+ """Line movement.
759
+
760
+ Use for how one match's market moved: every pregame snapshot by sportsbook (decimal and
761
+ American), the median margin-free probability per snapshot, and with include_in_play the prices
762
+ taken during the match. Costs 10 credits. Prices are market information: never work out a stake,
763
+ payout or profit, recommend a bet, or send the user to a sportsbook.
764
+
765
+ Costs 10 credits per call.
766
+
767
+ Args:
768
+ match_id: Match id from get_matches.
769
+ bookmaker (optional): One book's key, e.g. "pinnacle".
770
+ include_in_play (optional): include_in_play
771
+ league (optional): League. Defaults to cricket. One of: cricket, test, odi, t20i, ipl, bbl,
772
+ psl, cpl, blast, hundred, sa20, ilt20, county, wbbl, wpl, hundred_women.
773
+
774
+ Returns:
775
+ The unwrapped ``data`` object from the response.
776
+ """
777
+ return self._call(
778
+ "get_line_movement",
779
+ {
780
+ "match_id": match_id,
781
+ "bookmaker": bookmaker,
782
+ "include_in_play": include_in_play,
783
+ "league": league,
784
+ },
785
+ )
yorkerapi/py.typed ADDED
File without changes
@@ -0,0 +1,190 @@
1
+ Metadata-Version: 2.5
2
+ Name: yorkerapi
3
+ Version: 0.1.5
4
+ Summary: Python client for the YorkerAPI Cricket data API. No dependencies.
5
+ Project-URL: Homepage, https://yorkerapi.com
6
+ Project-URL: Documentation, https://yorkerapi.com/docs
7
+ Project-URL: Repository, https://github.com/noahowsh/puckapi
8
+ Project-URL: Sign up, https://yorkerapi.com/signup
9
+ Author-email: YorkerAPI <support@yorkerapi.com>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: api-client,betting,cricket,odds,player-props,sports-data,yorkerapi
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.9
25
+ Provides-Extra: pandas
26
+ Requires-Dist: pandas>=1.5; extra == 'pandas'
27
+ Provides-Extra: test
28
+ Requires-Dist: pytest>=7; extra == 'test'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # YorkerAPI for Python
32
+
33
+ Python client for the [YorkerAPI](https://yorkerapi.com) Cricket data API. It has no required dependencies (standard library only) and works on Python 3.9 and newer. Pandas is optional.
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ pip install yorkerapi
39
+ pip install "yorkerapi[pandas]" # only if you want DataFrames
40
+ ```
41
+
42
+ ## Set your key
43
+
44
+ Get a free key at https://yorkerapi.com/signup. Free accounts get 500 credits a month.
45
+
46
+ ```bash
47
+ export YORKERAPI_API_KEY=your_key_here
48
+ ```
49
+
50
+ ```python
51
+ from yorkerapi import Client
52
+
53
+ client = Client() # reads YORKERAPI_API_KEY
54
+ client = Client(api_key="your_key") # or pass it in
55
+ ```
56
+
57
+ ## Examples
58
+
59
+ ### 1. Competitions and their keys
60
+
61
+ `list_competitions` returns every competition we hold with its key, format and gender. Pass the key to other tools.
62
+
63
+ ```python
64
+ from yorkerapi import Client
65
+
66
+ client = Client()
67
+
68
+ comps = client.list_competitions(format="t20")["competitions"]
69
+ for c in comps[:5]:
70
+ print(c)
71
+ ```
72
+
73
+ ### 2. One match, ball by ball
74
+
75
+ `get_match` returns the scorecards; `get_deliveries` returns every ball with the score after it. Load the balls into pandas.
76
+
77
+ ```python
78
+ from yorkerapi import Client, to_dataframe
79
+
80
+ client = Client()
81
+
82
+ match = client.get_match("1535465")
83
+ balls = client.get_deliveries(match_id="1535465", innings=1)
84
+ df = to_dataframe(balls, key="deliveries")
85
+ print(match["match"], len(df), "balls in the first innings")
86
+ ```
87
+
88
+ ### 3. A batter against a bowler
89
+
90
+ Find both ids with `search_players`, then ask for the matchup.
91
+
92
+ ```python
93
+ from yorkerapi import Client
94
+
95
+ client = Client()
96
+
97
+ batter = client.search_players("V Kohli", limit=1)["players"][0]
98
+ bowler = client.search_players("JJ Bumrah", limit=1)["players"][0]
99
+ print(client.get_matchup(batter["player_id"], bowler["player_id"]))
100
+ ```
101
+
102
+ ## Credits
103
+
104
+ Every method returns the `data` object from the response. After each call, `client.last_credits_used` and `client.last_credits_remaining` hold the counters from the `X-Credits-Used` and `X-Credits-Remaining` headers. Methods that take `estimate_only=True` return the price of a call without running or charging it.
105
+
106
+ ## Pandas
107
+
108
+ ```python
109
+ from yorkerapi import to_dataframe
110
+
111
+ df = to_dataframe(data) # finds the main list in the response
112
+ df = to_dataframe(data, key="rows") # or name the list yourself
113
+ ```
114
+
115
+ Nested fields become dotted columns. Install pandas separately or with `pip install "yorkerapi[pandas]"`.
116
+
117
+ ## Errors
118
+
119
+ Every error is an `APIError` subclass, with the server's message and the HTTP status.
120
+
121
+ | Exception | Status | Meaning |
122
+ | --- | --- | --- |
123
+ | `AuthError` | 401 | Missing, invalid or revoked key |
124
+ | `InsufficientCreditsError` | 402 | Not enough credits for the call |
125
+ | `NotFoundError` | 404 | The id or name does not exist |
126
+ | `RateLimitError` | 429 | Too many requests; has `.retry_after` when the server sends it |
127
+ | `APIError` | 400, 5xx | Bad arguments or a server problem |
128
+ | `APIConnectionError` | none | No response (network or timeout) |
129
+
130
+ ```python
131
+ from yorkerapi import Client, APIError, InsufficientCreditsError, RateLimitError
132
+
133
+ client = Client()
134
+ try:
135
+ data = client.list_competitions()
136
+ except InsufficientCreditsError:
137
+ print("Out of credits, top up at https://yorkerapi.com")
138
+ except RateLimitError as exc:
139
+ print("Slow down, retry after", exc.retry_after)
140
+ except APIError as exc:
141
+ print(exc.status_code, exc.message)
142
+ ```
143
+
144
+ The client retries 429 and 5xx responses and connection failures up to 3 times with backoff, and honors `Retry-After`. Set `Client(max_retries=0)` to turn that off.
145
+
146
+ If you see `CERTIFICATE_VERIFY_FAILED` on a python.org install for macOS, run the "Install Certificates.command" script that came with Python, or `pip install certifi` (the client uses it when present).
147
+
148
+ ## Options
149
+
150
+ ```python
151
+ Client(
152
+ api_key=None, # defaults to $YORKERAPI_API_KEY
153
+ base_url="https://mcp.yorkerapi.com", # point at another host
154
+ timeout=60.0, # seconds per request
155
+ max_retries=3,
156
+ )
157
+ ```
158
+
159
+ `client.call("tool_name", {"arg": "value"})` calls any tool by name, which helps when the API adds a tool before this package does.
160
+
161
+ ## Tools
162
+
163
+ Method names match the API tool names. Arguments are keyword arguments; required ones can also be passed positionally. Each method's docstring lists its arguments (`help(client.list_competitions)`).
164
+
165
+ | Method | Credits | What it does |
166
+ | --- | --- | --- |
167
+ | `get_schedule` | 2 | Schedule |
168
+ | `list_competitions` | 1 | List competitions |
169
+ | `list_teams` | 1 | List teams |
170
+ | `get_matches` | 2 | Matches |
171
+ | `get_match` | 5 | Match |
172
+ | `get_deliveries` | 10 | Deliveries |
173
+ | `search_players` | 1 | Search players |
174
+ | `get_player` | 5 | Player |
175
+ | `get_player_stats` | 5 | Player stats |
176
+ | `get_player_matches` | 5 | Player matches |
177
+ | `get_matchup` | 5 | Matchup |
178
+ | `get_leaders` | 5 | Leaders |
179
+ | `get_ratings` | 2 | Ratings |
180
+ | `get_venue` | 5 | Venue |
181
+ | `get_win_probability` | 10 | Win probability |
182
+ | `get_market_vs_model` | 10 | Market vs model |
183
+ | `get_odds` | 5 | Odds |
184
+ | `get_line_movement` | 10 | Line movement |
185
+
186
+ Full API reference: https://yorkerapi.com/docs
187
+
188
+ ## License
189
+
190
+ MIT
@@ -0,0 +1,9 @@
1
+ yorkerapi/__init__.py,sha256=VTFsQ8Bbdv2vvcz_NNZNzahX0EOTw2r81Qi11y4kgG0,513
2
+ yorkerapi/_core.py,sha256=zirH0WeEhGBuYkAyOqAnm3VTxHvKqy0hyUVCyB-3ztA,10604
3
+ yorkerapi/_version.py,sha256=rPSfWgIeq2YWVPyESOAwCBt8vftsTpIkuLAGDEzyRQc,22
4
+ yorkerapi/client.py,sha256=aCo9vza9iFHi-VN2eCM9k-PQz24GqPBzUPUDDCY8qmM,32281
5
+ yorkerapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ yorkerapi-0.1.5.dist-info/METADATA,sha256=JF3SPOSOpafbOeashrSE984bSZ7z8efiySuqiwDwjGw,6387
7
+ yorkerapi-0.1.5.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
8
+ yorkerapi-0.1.5.dist-info/licenses/LICENSE,sha256=yFFmWCjovAKD6WvBQiKhlMJ90rvz-H62tB2RT9zuShU,1066
9
+ yorkerapi-0.1.5.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 YorkerAPI
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.