python-espncricinfo 0.5.8__tar.gz → 1.0.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.
Files changed (32) hide show
  1. python_espncricinfo-1.0.1/LICENSE.txt +22 -0
  2. python_espncricinfo-1.0.1/PKG-INFO +166 -0
  3. python_espncricinfo-1.0.1/README.md +133 -0
  4. python_espncricinfo-1.0.1/espncricinfo/__init__.py +1 -0
  5. python_espncricinfo-1.0.1/espncricinfo/_core.py +60 -0
  6. python_espncricinfo-1.0.1/espncricinfo/exceptions.py +25 -0
  7. python_espncricinfo-1.0.1/espncricinfo/match.py +693 -0
  8. python_espncricinfo-1.0.1/espncricinfo/match_ref.py +79 -0
  9. python_espncricinfo-1.0.1/espncricinfo/player.py +177 -0
  10. python_espncricinfo-1.0.1/espncricinfo/py.typed +0 -0
  11. python_espncricinfo-1.0.1/espncricinfo/seasons.py +95 -0
  12. python_espncricinfo-1.0.1/espncricinfo/series.py +128 -0
  13. python_espncricinfo-1.0.1/espncricinfo/summary.py +34 -0
  14. python_espncricinfo-1.0.1/espncricinfo/teams.py +106 -0
  15. python_espncricinfo-1.0.1/pyproject.toml +179 -0
  16. python_espncricinfo-1.0.1/pyproject.toml.orig +100 -0
  17. python-espncricinfo-0.5.8/PKG-INFO +0 -12
  18. python-espncricinfo-0.5.8/README.md +0 -71
  19. python-espncricinfo-0.5.8/espncricinfo/__init__.py +0 -1
  20. python-espncricinfo-0.5.8/espncricinfo/exceptions.py +0 -27
  21. python-espncricinfo-0.5.8/espncricinfo/match.py +0 -448
  22. python-espncricinfo-0.5.8/espncricinfo/player.py +0 -330
  23. python-espncricinfo-0.5.8/espncricinfo/series.py +0 -78
  24. python-espncricinfo-0.5.8/espncricinfo/summary.py +0 -34
  25. python-espncricinfo-0.5.8/python_espncricinfo.egg-info/PKG-INFO +0 -12
  26. python-espncricinfo-0.5.8/python_espncricinfo.egg-info/SOURCES.txt +0 -15
  27. python-espncricinfo-0.5.8/python_espncricinfo.egg-info/dependency_links.txt +0 -1
  28. python-espncricinfo-0.5.8/python_espncricinfo.egg-info/requires.txt +0 -3
  29. python-espncricinfo-0.5.8/python_espncricinfo.egg-info/top_level.txt +0 -1
  30. python-espncricinfo-0.5.8/python_espncricinfo.egg-info/zip-safe +0 -1
  31. python-espncricinfo-0.5.8/setup.cfg +0 -7
  32. python-espncricinfo-0.5.8/setup.py +0 -17
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Derek Willis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,166 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-espncricinfo
3
+ Version: 1.0.1
4
+ Summary: Python client for ESPNcricinfo match, series, season, team and player data
5
+ Keywords: espncricinfo,cricket,t20,odi,test cricket,scorecard,sports data
6
+ Author: Derek Willis, Gaurav Sood
7
+ Author-email: Derek Willis <dwillis@gmail.com>, Gaurav Sood <gsood07@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE.txt
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Topic :: Internet :: WWW/HTTP
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Dist: requests
22
+ Requires-Dist: beautifulsoup4
23
+ Requires-Dist: dateparser
24
+ Requires-Dist: lxml
25
+ Requires-Dist: playwright>=1.48.0
26
+ Requires-Python: >=3.12
27
+ Project-URL: Homepage, https://github.com/outside-edge/python-espncricinfo
28
+ Project-URL: Repository, https://github.com/outside-edge/python-espncricinfo
29
+ Project-URL: Documentation, https://outside-edge.github.io/python-espncricinfo/
30
+ Project-URL: Changelog, https://github.com/outside-edge/python-espncricinfo/blob/master/CHANGELOG.md
31
+ Project-URL: Issues, https://github.com/outside-edge/python-espncricinfo/issues
32
+ Description-Content-Type: text/markdown
33
+
34
+ # python-espncricinfo
35
+
36
+ [![PyPI](https://img.shields.io/pypi/v/python-espncricinfo)](https://pypi.org/project/python-espncricinfo/)
37
+ [![Downloads](https://static.pepy.tech/badge/python-espncricinfo)](https://pepy.tech/projects/python-espncricinfo)
38
+ [![CI](https://github.com/outside-edge/python-espncricinfo/actions/workflows/ci.yml/badge.svg)](https://github.com/outside-edge/python-espncricinfo/actions/workflows/ci.yml)
39
+ [![Docs](https://github.com/outside-edge/python-espncricinfo/actions/workflows/docs.yml/badge.svg)](https://outside-edge.github.io/python-espncricinfo/)
40
+ [![Python](https://img.shields.io/pypi/pyversions/python-espncricinfo)](https://pypi.org/project/python-espncricinfo/)
41
+
42
+ <!-- SPHINX-START -->
43
+
44
+ A Python client for ESPNcricinfo match, series, season, team and player data.
45
+
46
+ ## Description
47
+
48
+ Match pages are loaded with Playwright (WebKit), because ESPN's CDN refuses plain HTTP clients; player, series, season and team records come from ESPN's core JSON API. A `Match` needs both a `match_id` and a `series_id`, which `Match.get_recent_matches()` and `Series(...).matches` provide.
49
+
50
+ Disclaimer: This library is not intended for commercial use and neither it nor its creator has any affiliation with ESPNCricInfo. The [LICENSE](https://github.com/outside-edge/python-espncricinfo/blob/master/LICENSE.txt) for this library applies only to the code, not to the data.
51
+
52
+ ## Installation
53
+
54
+ ```shell
55
+ uv add python-espncricinfo
56
+ ```
57
+
58
+ Or with pip:
59
+
60
+ ```shell
61
+ pip install python-espncricinfo
62
+ ```
63
+
64
+ After installation, install the Playwright WebKit browser (required for fetching match data):
65
+
66
+ ```shell
67
+ uv run playwright install webkit
68
+ ```
69
+
70
+ <!-- USAGE-START -->
71
+
72
+ ## Recent matches
73
+
74
+ `Summary().matches` lists the matches on ESPNcricinfo's results page. Pass a date to look back; ESPN returns about two weeks of matches ending on that day.
75
+
76
+ ```python
77
+ >>> from espncricinfo.match import Match
78
+ >>> refs = Match.get_recent_matches(date="2026-02-28")
79
+ >>> len(refs)
80
+ 195
81
+ >>> refs[0]
82
+ MatchRef(series_id=1523975, match_id=1523981)
83
+ >>> series_id, match_id = refs[0] # MatchRefs unpack like tuples
84
+ ```
85
+
86
+ `Summary(date=...)` wraps the same call; its result is in `.matches`.
87
+
88
+ ## A single match
89
+
90
+ A match needs both its match ID and series ID: the two numbers in a match page URL, or a `MatchRef`. Loading a match starts a headless WebKit browser.
91
+
92
+ ```python
93
+ >>> m = Match(1478914, 1478874) # same as MatchRef(1478874, 1478914).to_match()
94
+ >>> m.description
95
+ 'IND Women v AUS Women'
96
+ >>> m.match_class
97
+ 'WT20I'
98
+ >>> m.result
99
+ 'IND Women won by 17 runs'
100
+ >>> m.batting_scorecard[0][0]["name"], m.batting_scorecard[0][0]["runs"]
101
+ ('S Mandhana', 82)
102
+ >>> m.bowling_scorecard[0][0]["name"], m.bowling_scorecard[0][0]["wickets"]
103
+ ('D Brown', 0)
104
+ ```
105
+
106
+ `batting_scorecard` and `bowling_scorecard` hold one list per innings and one dict per player.
107
+
108
+ ## Players
109
+
110
+ The player ID is the number at the end of a player's profile URL.
111
+
112
+ ```python
113
+ >>> from espncricinfo.player import Player
114
+ >>> p = Player(277916)
115
+ >>> p.full_name
116
+ 'Ajinkya Madhukar Rahane'
117
+ >>> p.get_data(file_name="rahane_tests.csv", match_format=1, data_type="batting")
118
+ ```
119
+
120
+ `get_data` writes one row per match (85 Tests for Rahane); `get_career_summary` and `get_career_averages` write the summary tables from the same Statsguru page.
121
+
122
+ ## Series, seasons and teams
123
+
124
+ ```python
125
+ >>> from espncricinfo.series import Series
126
+ >>> ipl = Series(1449924)
127
+ >>> ipl.name
128
+ 'Indian Premier League'
129
+ >>> season = ipl.current_season
130
+ >>> season.year, len(season.teams)
131
+ (2025, 10)
132
+ >>> season.teams[0].name
133
+ 'Chennai Super Kings'
134
+ ```
135
+
136
+ `series.season_objects` lists every season and `season.match_refs` that season's matches. `series.matches` collects MatchRefs across all seasons (1,254 for the IPL), and `series.current_matches` keeps those in progress. `team.players` loads the squad on demand. ESPN's records for some bilateral tours are incomplete, for example listing one team for a two-team series.
137
+
138
+ <!-- USAGE-END -->
139
+
140
+ ## Development
141
+
142
+ <!-- DEV-START -->
143
+
144
+ **Unit tests** (no network required — uses recorded fixtures):
145
+
146
+ ```shell
147
+ uv run pytest
148
+ ```
149
+
150
+ **Integration tests** (hits live ESPN Cricinfo via Playwright):
151
+
152
+ ```shell
153
+ uv run pytest --live
154
+ ```
155
+
156
+ **Refreshing fixtures** (re-records fixtures from live site):
157
+
158
+ ```shell
159
+ uv run python scripts/refresh_fixtures.py
160
+ ```
161
+
162
+ Integration tests and the fixture refresh need the WebKit browser:
163
+
164
+ ```shell
165
+ uv run playwright install webkit
166
+ ```
@@ -0,0 +1,133 @@
1
+ # python-espncricinfo
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/python-espncricinfo)](https://pypi.org/project/python-espncricinfo/)
4
+ [![Downloads](https://static.pepy.tech/badge/python-espncricinfo)](https://pepy.tech/projects/python-espncricinfo)
5
+ [![CI](https://github.com/outside-edge/python-espncricinfo/actions/workflows/ci.yml/badge.svg)](https://github.com/outside-edge/python-espncricinfo/actions/workflows/ci.yml)
6
+ [![Docs](https://github.com/outside-edge/python-espncricinfo/actions/workflows/docs.yml/badge.svg)](https://outside-edge.github.io/python-espncricinfo/)
7
+ [![Python](https://img.shields.io/pypi/pyversions/python-espncricinfo)](https://pypi.org/project/python-espncricinfo/)
8
+
9
+ <!-- SPHINX-START -->
10
+
11
+ A Python client for ESPNcricinfo match, series, season, team and player data.
12
+
13
+ ## Description
14
+
15
+ Match pages are loaded with Playwright (WebKit), because ESPN's CDN refuses plain HTTP clients; player, series, season and team records come from ESPN's core JSON API. A `Match` needs both a `match_id` and a `series_id`, which `Match.get_recent_matches()` and `Series(...).matches` provide.
16
+
17
+ Disclaimer: This library is not intended for commercial use and neither it nor its creator has any affiliation with ESPNCricInfo. The [LICENSE](https://github.com/outside-edge/python-espncricinfo/blob/master/LICENSE.txt) for this library applies only to the code, not to the data.
18
+
19
+ ## Installation
20
+
21
+ ```shell
22
+ uv add python-espncricinfo
23
+ ```
24
+
25
+ Or with pip:
26
+
27
+ ```shell
28
+ pip install python-espncricinfo
29
+ ```
30
+
31
+ After installation, install the Playwright WebKit browser (required for fetching match data):
32
+
33
+ ```shell
34
+ uv run playwright install webkit
35
+ ```
36
+
37
+ <!-- USAGE-START -->
38
+
39
+ ## Recent matches
40
+
41
+ `Summary().matches` lists the matches on ESPNcricinfo's results page. Pass a date to look back; ESPN returns about two weeks of matches ending on that day.
42
+
43
+ ```python
44
+ >>> from espncricinfo.match import Match
45
+ >>> refs = Match.get_recent_matches(date="2026-02-28")
46
+ >>> len(refs)
47
+ 195
48
+ >>> refs[0]
49
+ MatchRef(series_id=1523975, match_id=1523981)
50
+ >>> series_id, match_id = refs[0] # MatchRefs unpack like tuples
51
+ ```
52
+
53
+ `Summary(date=...)` wraps the same call; its result is in `.matches`.
54
+
55
+ ## A single match
56
+
57
+ A match needs both its match ID and series ID: the two numbers in a match page URL, or a `MatchRef`. Loading a match starts a headless WebKit browser.
58
+
59
+ ```python
60
+ >>> m = Match(1478914, 1478874) # same as MatchRef(1478874, 1478914).to_match()
61
+ >>> m.description
62
+ 'IND Women v AUS Women'
63
+ >>> m.match_class
64
+ 'WT20I'
65
+ >>> m.result
66
+ 'IND Women won by 17 runs'
67
+ >>> m.batting_scorecard[0][0]["name"], m.batting_scorecard[0][0]["runs"]
68
+ ('S Mandhana', 82)
69
+ >>> m.bowling_scorecard[0][0]["name"], m.bowling_scorecard[0][0]["wickets"]
70
+ ('D Brown', 0)
71
+ ```
72
+
73
+ `batting_scorecard` and `bowling_scorecard` hold one list per innings and one dict per player.
74
+
75
+ ## Players
76
+
77
+ The player ID is the number at the end of a player's profile URL.
78
+
79
+ ```python
80
+ >>> from espncricinfo.player import Player
81
+ >>> p = Player(277916)
82
+ >>> p.full_name
83
+ 'Ajinkya Madhukar Rahane'
84
+ >>> p.get_data(file_name="rahane_tests.csv", match_format=1, data_type="batting")
85
+ ```
86
+
87
+ `get_data` writes one row per match (85 Tests for Rahane); `get_career_summary` and `get_career_averages` write the summary tables from the same Statsguru page.
88
+
89
+ ## Series, seasons and teams
90
+
91
+ ```python
92
+ >>> from espncricinfo.series import Series
93
+ >>> ipl = Series(1449924)
94
+ >>> ipl.name
95
+ 'Indian Premier League'
96
+ >>> season = ipl.current_season
97
+ >>> season.year, len(season.teams)
98
+ (2025, 10)
99
+ >>> season.teams[0].name
100
+ 'Chennai Super Kings'
101
+ ```
102
+
103
+ `series.season_objects` lists every season and `season.match_refs` that season's matches. `series.matches` collects MatchRefs across all seasons (1,254 for the IPL), and `series.current_matches` keeps those in progress. `team.players` loads the squad on demand. ESPN's records for some bilateral tours are incomplete, for example listing one team for a two-team series.
104
+
105
+ <!-- USAGE-END -->
106
+
107
+ ## Development
108
+
109
+ <!-- DEV-START -->
110
+
111
+ **Unit tests** (no network required — uses recorded fixtures):
112
+
113
+ ```shell
114
+ uv run pytest
115
+ ```
116
+
117
+ **Integration tests** (hits live ESPN Cricinfo via Playwright):
118
+
119
+ ```shell
120
+ uv run pytest --live
121
+ ```
122
+
123
+ **Refreshing fixtures** (re-records fixtures from live site):
124
+
125
+ ```shell
126
+ uv run python scripts/refresh_fixtures.py
127
+ ```
128
+
129
+ Integration tests and the fixture refresh need the WebKit browser:
130
+
131
+ ```shell
132
+ uv run playwright install webkit
133
+ ```
@@ -0,0 +1 @@
1
+ """Python client for ESPNcricinfo match, series, season, team and player data."""
@@ -0,0 +1,60 @@
1
+ """Shared HTTP and reference helpers for the ESPN core API."""
2
+
3
+ import re
4
+
5
+ import requests
6
+ from requests.adapters import HTTPAdapter
7
+ from urllib3.util import Retry
8
+
9
+ HEADERS = {"user-agent": "Mozilla/5.0"}
10
+ TIMEOUT = 30
11
+
12
+ # ESPN's core API intermittently answers "503 Backend fetch failed". A player's
13
+ # major teams take one request each, so without retries one blip fails the call.
14
+ # raise_on_status=False hands back the last response after the retries, so
15
+ # callers keep their own 404 and raise_for_status handling.
16
+ _RETRY = Retry(
17
+ total=3,
18
+ backoff_factor=0.5,
19
+ status_forcelist=(500, 502, 503, 504),
20
+ allowed_methods=("GET",),
21
+ raise_on_status=False,
22
+ )
23
+ _SESSION = requests.Session()
24
+ _SESSION.mount("http://", HTTPAdapter(max_retries=_RETRY))
25
+ _SESSION.mount("https://", HTTPAdapter(max_retries=_RETRY))
26
+
27
+
28
+ def http_get(url, headers=None):
29
+ """GET ``url`` with the shared timeout and retry policy."""
30
+ return _SESSION.get(url, headers=headers or HEADERS, timeout=TIMEOUT)
31
+
32
+
33
+ def reference_ids(url, resource):
34
+ """Return the (series_id, resource_id) pair from a core API reference URL."""
35
+ match = re.search(rf"/leagues/(\d+)/{resource}/(\d+)(?:/|$)", url)
36
+ if match is None:
37
+ raise ValueError(f"Invalid {resource} reference: {url}")
38
+ return int(match.group(1)), int(match.group(2))
39
+
40
+
41
+ def get_json(url, not_found_error):
42
+ """Return the JSON at ``url``; raise ``not_found_error`` on 404."""
43
+ response = http_get(url)
44
+ if response.status_code == 404:
45
+ raise not_found_error(f"Not found: {url}")
46
+ response.raise_for_status()
47
+ return response.json()
48
+
49
+
50
+ def collection_refs(url, not_found_error):
51
+ """Return every ``$ref`` in a paginated core API collection."""
52
+ references = []
53
+ page = 1
54
+ while True:
55
+ page_url = url if page == 1 else f"{url}?page={page}"
56
+ data = get_json(page_url, not_found_error)
57
+ references.extend(item["$ref"] for item in data.get("items", []))
58
+ if page >= data.get("pageCount", 1):
59
+ return references
60
+ page += 1
@@ -0,0 +1,25 @@
1
+ """Exceptions raised by python-espncricinfo."""
2
+
3
+
4
+ class MatchNotFoundError(TypeError):
5
+ """Raised when a match_id is not valid or does not exist."""
6
+
7
+
8
+ class PlayerNotFoundError(TypeError):
9
+ """Raised when a player_id is not valid or does not exist."""
10
+
11
+
12
+ class NoScorecardError(TypeError):
13
+ """Raised when a match has no scorecard."""
14
+
15
+
16
+ class NoSeriesError(TypeError):
17
+ """Raised when a series_id is not valid or does not exist."""
18
+
19
+
20
+ class NoSeasonError(TypeError):
21
+ """Exception raised if a season does not exist."""
22
+
23
+
24
+ class NoTeamError(TypeError):
25
+ """Exception raised if a team does not exist in a series."""